RE : Regular expressions

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default RE : Regular expressions

    Actually, I have to test two conditions to get into a block,

    If the strings found are either "one two" or "two three", go ahead.

    if ($text =~ /one two/ or /two three/)

    Steve Hemond
    Programmeur Analyste / Analyst Programmer
    Smurfit-Stone, Ressources Forestières
    La Tuque, P.Q.
    Tel.: (819) 676-8100 X2833
    [email]shemond@smurfit.com[/email]


    > -----Original Message-----
    > From: James Edward Gray II [mailto:james@grayproductions.net]
    > Sent: Wednesday, December 17, 2003 11:05 AM
    > To: Hemond, Steve
    > Cc: [email]beginners@perl.org[/email]
    > Subject: Re: Regular expressions
    >
    >
    > On Dec 17, 2003, at 9:59 AM, Hemond, Steve wrote:
    >
    > > Hi again,
    > >
    > > I want to make a search on two words.
    > >
    > > If 'one two' is found, it is okay.
    > > If 'one' is found, it is incorrect.
    > > If 'two' is found, it is also incorrect.
    > >
    > > I want the search to return me occurences of 'one two'
    > found together.
    > >
    > > I am searching this way :
    > > if ($text =~ /one two/)
    > >
    > > What I am doing wrong?
    >
    > Nothing that I can see. Although, /\bone two\b/ is probably
    > slightly
    > better. What's the problem?
    >
    > James
    >
    Steve Hemond Guest

  2. Similar Questions and Discussions

    1. RE : RE : Regular expressions
      I think I begin to understand... I begin by fetching the results of the ps -efA command and split it into many variables ($uid, $pid, etc.) ...
    2. [PHP] Q on Regular Expressions
      * Thus wrote jsWalter (jsWalter@torres.ws): have you looked at strtotime()? http://php.net/strtotime The Date formats it can find are defined...
    3. [PHP-DEV] PHP regular expressions
      Hello. In regex/utils.h there is a definition for DUPMAX: #ifdef _POSIX2_RE_DUP_MAX #define DUPMAX _POSIX2_RE_DUP_MAX #else #define DUPMAX 255...
    4. Help with regular expressions.
      Apples and Oranges: I think your format string is wrong, try: {0:d} "Pablo Pecora" <pablo.pecora@itau.com.ar> wrote in message...
    5. help with regular expressions
      Hello, just getting grips with Perl and RE, but need your help. I am trying to open a file, print its contents to a textbox, but extract...
  3. #2

    Default Re: RE : Regular expressions

    On Dec 17, Hemond, Steve said:
    >Actually, I have to test two conditions to get into a block,
    >
    >If the strings found are either "one two" or "two three", go ahead.
    >
    >if ($text =~ /one two/ or /two three/)
    That code is the same as

    if (($text =~ /one two/) or ($_ =~ /two three/)) { ... }

    You want either

    if ($text =~ /one two/ or $text =~ /two three/) { ... }

    or

    if ($text =~ /one two|two three/) { ... }

    --
    Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
    RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
    <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
    [ I'm looking for programming work. If you like my work, let me know. ]

    Jeff 'Japhy' Pinyan Guest

  4. #3

    Default Re: RE : Regular expressions

    On Dec 17, 2003, at 10:09 AM, Hemond, Steve wrote:
    > Actually, I have to test two conditions to get into a block,
    >
    > If the strings found are either "one two" or "two three", go ahead.
    >
    > if ($text =~ /one two/ or /two three/)
    Now that is a mistake. ;)

    if ($text =~ /\bone two\b/ || $text =~ /\btwo three\b/) {

    James

    James Edward Gray II Guest

  5. #4

    Default RE : Regular expressions

    Okay, here`s the real problem,

    # ps -efA |grep dispatch
    cspenard 33958 45716 0 09:08:05 pts/8 0:00 /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
    msirois 37212 9842 0 08:41:17 pts/1 0:04 /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im

    My script passes each process and when it finds "dispatch genie" it holds its data in a hash table.

    As you can see, dispatch genie is found in these two columns.

    if ($cmd =~ /dispatch genie/) {

    That returns absolutely nothing.

    Why?

    Steve Hemond
    Programmeur Analyste / Analyst Programmer
    Smurfit-Stone, Ressources Forestières
    La Tuque, P.Q.
    Tel.: (819) 676-8100 X2833
    [email]shemond@smurfit.com[/email]


    > -----Original Message-----
    > From: drieux [mailto:drieux@wetware.com]
    > Sent: Wednesday, December 17, 2003 11:24 AM
    > To: Perl Perl
    > Subject: Re: Regular expressions
    >
    >
    >
    > On Dec 17, 2003, at 7:59 AM, Hemond, Steve wrote:
    > [..]
    > > I am searching this way :
    > > if ($text =~ /one two/)
    > >
    > > What I am doing wrong?
    >
    > ok, I bite, what is the problem?
    >
    > given
    > #!/usr/bin/perl -w
    > use strict;
    >
    > while ( <DATA> ) {
    > my $text = $_;
    > if ($text =~ /one two/)
    > {
    > print "line is ok:\n\t$text";
    > } else {
    > print "WRONG!\n\t$text";
    > }
    > }
    >
    > __DATA__
    > If 'one two' is found, it is okay.
    > If 'one' is found, it is incorrect.
    > If 'two' is found, it is also incorrect.
    >
    > we get
    > line is ok:
    > If 'one two' is found, it is okay.
    > WRONG!
    > If 'one' is found, it is incorrect.
    > WRONG!
    > If 'two' is found, it is also incorrect.
    >
    > What Problem?
    >
    >
    > ciao
    > drieux
    >
    > ---
    >
    >
    > --
    > To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
    > For additional commands, e-mail: [email]beginners-help@perl.org[/email]
    <http://learn.perl.org/> <http://learn.perl.org/first-response>

    Steve Hemond Guest

  6. #5

    Default Re: RE : Regular expressions

    On Dec 17, 2003, at 10:29 AM, Hemond, Steve wrote:
    > Okay, here`s the real problem,
    >
    > # ps -efA |grep dispatch
    > cspenard 33958 45716 0 09:08:05 pts/8 0:00
    > /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
    > msirois 37212 9842 0 08:41:17 pts/1 0:04
    > /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
    >
    > My script passes each process and when it finds "dispatch genie" it
    > holds its data in a hash table.
    >
    > As you can see, dispatch genie is found in these two columns.
    >
    > if ($cmd =~ /dispatch genie/) {
    >
    > That returns absolutely nothing.
    >
    > Why?
    "returns nothing" is a little confusing. The test above should
    evaluate to true, if $cmd contains 'dispatch genie' and whatever is
    inside the if block should be executed. If you're saying the if block
    isn't being executed, well $cmd probably doesn't contain what you think
    it does then.

    James

    James Edward Gray II Guest

  7. #6

    Default RE: RE : Regular expressions

    Hemond, Steve wrote:
    > Okay, here`s the real problem,
    >
    > # ps -efA |grep dispatch
    > cspenard 33958 45716 0 09:08:05 pts/8 0:00
    > /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
    > msirois 37212 9842 0 08:41:17 pts/1 0:04
    > /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
    >
    > My script passes each process and when it finds "dispatch genie" it
    > holds its data in a hash table.
    >
    > As you can see, dispatch genie is found in these two columns.
    >
    > if ($cmd =~ /dispatch genie/) {
    >
    > That returns absolutely nothing.
    >
    > Why?
    >

    Again, that regexp works just fine. (If you're setting $cmd properly...)
    Something else must be wrong that you're not sending in your email
    requests. Send the actual code.

    #!/usr/bin/perl -w
    use warnings;
    use strict;

    while (<DATA>) {
    chomp;
    (/dispatch genie/) ? print "Hit\n" : print "Miss\n";
    }

    __DATA__
    cspenard 33958 45716 0 09:08:05 pts/8 0:00
    /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
    msirois 37212 9842 0 08:41:17 pts/1 0:04
    /prog/gena/8.1.1/bin/dispatch genie -u /prog/gena/impress/gui/im
    Ed Christian Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139