need some help in multiple pattern replacement

Discussion in 'Perl Misc' started by inderpaul_s@yahoo.com, Apr 16, 2006.

  1. Guest

    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";
     
    , Apr 16, 2006
    #1
    1. Advertising

  2. Guest

    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";
     
    , Apr 16, 2006
    #2
    1. Advertising

  3. wrote:
    > 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
    --
    use Perl;
    program
    fulfillment
     
    John W. Krahn, Apr 16, 2006
    #3
  4. Guest

    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;
     
    , Apr 16, 2006
    #4
  5. Guest

    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)
     
    , Apr 16, 2006
    #5
  6. wrote:
    > 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
     
    Jürgen Exner, Apr 16, 2006
    #6
  7. Guest

    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
     
    , Apr 16, 2006
    #7
  8. Guest

    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
     
    , Apr 16, 2006
    #8
  9. Guest

    wrote:
    > 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.
     
    , Apr 16, 2006
    #9
  10. Guest

    d wrote:
    > wrote:
    > > 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.


    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 ?
     
    , Apr 16, 2006
    #10
  11. OmarDes Guest

    d wrote:
    > wrote:
    > > 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.


    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 ?
     
    OmarDes, Apr 16, 2006
    #11
  12. <> wrote:

    > thanks



    Thank who for what?


    > print "$string";



    perldoc -q vars

    What's wrong with always quoting "$vars"?


    so make that:

    print $string;


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Apr 16, 2006
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    0
    Views:
    684
    Guest
    Feb 25, 2004
  2. Jarkko Viinamäki
    Replies:
    1
    Views:
    4,184
    =?ISO-8859-1?Q?Daniel_Sj=F6blom?=
    Feb 22, 2004
  3. Replies:
    9
    Views:
    5,328
    Lasse Reichstein Nielsen
    Mar 12, 2006
  4. tom

    pattern replacement in xml

    tom, Jun 21, 2005, in forum: Perl Misc
    Replies:
    6
    Views:
    160
    John Bokma
    Jun 22, 2005
  5. tom

    replacement pattern

    tom, Jun 23, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    110
    Greg Bacon
    Jun 23, 2005
Loading...

Share This Page