need some help in multiple pattern replacement

I

inderpaul_s

I'm just trying to replace the words "hello" and "how" with "who" in
both cases in one single pattern expression. how can i do this ?

my $string = "hello how are you ?"

$string =~ s/(hello)(are)/who)/g;
print "$string";
 
I

inderpaul_s

thanks i just kept working at and found the solution. I just didn't
know that the space character was needed between the replacement items.


$string =~ s/(hello).(how)/who who/g;
print "$string";
 
J

John W. Krahn

I'm just trying to replace the words "hello" and "how" with "who" in
both cases in one single pattern expression. how can i do this ?

my $string = "hello how are you ?"

$string =~ s/(hello)(are)/who)/g;

$string =~ s/hello|how/who/g;

Or perhaps you meant:

$string =~ s/hello +how/who who/;


John
 
I

inderpaul_s

discarding my last followup (apparently it doesn't work) I have found
that in order for my code to work I need to substitute replace any in
between text as in my code here....Is there any other way to do this
assuming we don't know the structure of the incoming string...The only
thing I'm trying to accomplish here is how to search and replace more
then one string ina single substitute expression statement as asked in
my very first post. Thank you again

my $string = "hello how are you ?";
$string =~ s/(hello)(.+)(you)/0 $2 1/g;
 
I

inderpaul_s

thanks John didn't see this post before I made my third (3) submission.
thanks for information on the pipe wasn't aware of that but I'd like to
replace each item in (...) with separate replacement items instead of
who who maybe just 0 1 just for the sake of clearity. (sorry my
original post was far from clear)
 
J

Jürgen Exner

thanks John didn't see this post

You have been asked several times to quote appropriate context when replying
to a posting as has been customary for 2 decades.
Obviously you have no intention to follow that advise.

I for my part had enough. So long then.

jue
 
I

inderpaul_s

Sorry Jurgen but thats not true I have not been asked to quote nor have
I done on purpose I rarely participate on groups so I don't know all of
the etiquete...my apologies to everyone
 
I

inderpaul_s

Sorry Jurgen but thats not true I have not been asked to quote nor have
I done on purpose I rarely participate on groups so I don't know all of
the etiquete...my apologies to everyone
 
1

1usa

Sorry Jurgen but thats not true I have not been asked to quote nor have
I done on purpose I rarely participate on groups so I don't know all of
the etiquete...my apologies to everyone

Your apology is not genuine as you still did not quote any context.

Anyway, you were asked at least once before to quote context:

http://groups.google.com/group/comp.lang.perl.misc/msg/9fc3112f4d1a6b0a

Sinan

PS: You are already in my killfile, I just stumbled upon this thread
while searching for something else.
 
I

inderpaul_s

Your apology is not genuine as you still did not quote any context.

Anyway, you were asked at least once before to quote context:

http://groups.google.com/group/comp.lang.perl.misc/msg/9fc3112f4d1a6b0a

Sinan

PS: You are already in my killfile, I just stumbled upon this thread
while searching for something else.

Well I finally figured out how google groups allow you to quote
text....obviously yourself and Jurgen didn't the remote chance that I
just didn't know how ?
 
O

OmarDes

Your apology is not genuine as you still did not quote any context.

Anyway, you were asked at least once before to quote context:

http://groups.google.com/group/comp.lang.perl.misc/msg/9fc3112f4d1a6b0a

Sinan

PS: You are already in my killfile, I just stumbled upon this thread
while searching for something else.

Hello San. Good to see your working tonight's watch...give the boy a
chance ? I'm sure you weren't on your best behavious when you entered
the usenet scene...I'm sure he'll learn...

Now as for Mr. inderpaul_s...just a little piece of advise son
learn...and learn quickly the rules of the game as I'm sure San can
easily fill you in on. Am I right San or not ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top