If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > replacing text????

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-06, 05:13
jagans jagans is offline
Registered User
 
Join Date: Jul 2004
Posts: 48
replacing text????

hi all..
i want to replace some texts from a string
4eg
$str='this is my test document and was created in perl and it is very goodis"
out of this string i want to replace all 'is' and 'was' with 'are' how i wil do it
rem ny string contains substrings eg (is in 'goodis' Ii don't want to replace it
pls help me
thnks in advance
jag
Reply With Quote
  #2 (permalink)  
Old 02-10-06, 13:33
KevinADC KevinADC is offline
Registered User
 
Join Date: Feb 2006
Posts: 56
use the word boundary operator \b

Code:
my $str = 'this is my test document and was created in perl and it is very goodis';
$str =~ s/\bis|was\b/are/ig;
print $str;
or you could try and use spaces:

Code:
my $str = 'this is my test document and was created in perl and it is very goodis';
$str =~ s/\sis|was\s/are/ig;
print $str;
but the \b operator is generally used for this type of substitution. Any regexp resource or tutorial should have it listed.
Reply With Quote
  #3 (permalink)  
Old 02-10-06, 13:34
hyperbole hyperbole is offline
Registered User
 
Join Date: Jan 2006
Posts: 32
I assume you want to make the change in perl.

use
Code:
$string =~ s/\bis\b/was/g;
\b is a zero width match that matches only on a word boundary.



.
Reply With Quote
  #4 (permalink)  
Old 02-15-06, 23:45
jagans jagans is offline
Registered User
 
Join Date: Jul 2004
Posts: 48
thnks!!!!!

hi all
i'd try it and its working thnk u verymuch
but the problem is whn i add more choices some textes(means substrings) are missing
neway thnks 4 ur help
bye
jag
Reply With Quote
  #5 (permalink)  
Old 02-16-06, 04:29
reneeb reneeb is offline
Registered User
 
Join Date: Jan 2004
Location: Germany
Posts: 167
Can you post some more details about the problem?

You should post some Dummy data and code...
__________________
board.perl-community.de - The German Perl-Community
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On