Perl regular expressions

Discussion in 'Perl Misc' started by Alona, Feb 1, 2008.

  1. Alona

    Alona Guest

    Hello All,

    We need to extract from a text a 3-digit numbers surrounded by certain
    text. For example, we need to extract 199 surrounded by "MESSAGE TYPE"
    and "SYSTEM/INPUT":

    MESSAGE TYPE 199 SYSTEM/INPUT

    What would be Perl regular expression for this?

    Thank you,
    Alona
    Alona, Feb 1, 2008
    #1
    1. Advertising

  2. Alona

    J. Gleixner Guest

    Alona wrote:
    > Hello All,
    >
    > We need to extract from a text a 3-digit numbers surrounded by certain
    > text. For example, we need to extract 199 surrounded by "MESSAGE TYPE"
    > and "SYSTEM/INPUT":
    >
    > MESSAGE TYPE 199 SYSTEM/INPUT
    >
    > What would be Perl regular expression for this?


    This is regular expression 101. What have you tried?
    J. Gleixner, Feb 1, 2008
    #2
    1. Advertising

  3. On Fri, 01 Feb 2008 13:58:10 -0800, Alona wrote:

    > Hello All,
    >
    > We need to extract from a text a 3-digit numbers surrounded by certain
    > text. For example, we need to extract 199 surrounded by "MESSAGE TYPE"
    > and "SYSTEM/INPUT":
    >
    > MESSAGE TYPE 199 SYSTEM/INPUT
    >
    > What would be Perl regular expression for this?


    If you read perldoc perlre you would quickly see that this would be

    /MESSAGE TYPE (\d+) SYSTEM\/INPUT/

    HTH,
    M4
    Martijn Lievaart, Feb 1, 2008
    #3
  4. Alona

    Henry Law Guest

    Alona wrote:
    > Hello All,
    >
    > We need to extract from a text a 3-digit numbers surrounded by certain
    > text. For example, we need to extract 199 surrounded by "MESSAGE TYPE"
    > and "SYSTEM/INPUT":
    >
    > MESSAGE TYPE 199 SYSTEM/INPUT
    >
    > What would be Perl regular expression for this?


    $yourtext =~ m!MESSAGE TYPE (\d{3}) SYSTEM/INPUT!;

    Now, what is your real question? It will take you a long time to get
    your program written one line at a time.

    --

    Henry Law Manchester, England
    Henry Law, Feb 1, 2008
    #4
  5. Alona <> wrote:


    > We need to extract from a text a 3-digit numbers surrounded by certain
    > text. For example, we need to extract 199 surrounded by "MESSAGE TYPE"
    > and "SYSTEM/INPUT":
    >
    > MESSAGE TYPE 199 SYSTEM/INPUT



    my $num = substr( $_, index($_, 'SYSTEM/INPUT')-4, 3);


    > What would be Perl regular expression for this?



    Look Ma! No regular expression at all!

    :)


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
    Tad J McClellan, Feb 2, 2008
    #5
  6. Alona

    Alona Guest

    On Feb 1, 9:09 pm, Tad J McClellan <> wrote:
    > Alona <> wrote:
    > > We need to extract from a text a 3-digit numbers surrounded by certain
    > > text. For example, we need to extract 199 surrounded by "MESSAGE TYPE"
    > > and "SYSTEM/INPUT":

    >
    > > MESSAGE TYPE 199 SYSTEM/INPUT

    >
    >    my $num = substr( $_, index($_, 'SYSTEM/INPUT')-4, 3);
    >
    > > What would be Perl regular expression for this?

    >
    > Look Ma! No regular expression at all!
    >
    > :)
    >
    > --
    > Tad McClellan
    > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"




    Thank you all. Please notice that we are searching for 199 in a
    certain context. We are not interested in finding "MESSAGE TYPE" and
    "SYSTEM/INPUT". We are only interested in 199, but the match should
    only pick 199's surrounded in the text by MESSAGE TYPE adn SYSTEM/
    INPUT.

    Thanks,
    Alona
    Alona, Feb 2, 2008
    #6
  7. Alona

    Alona Guest

    On Feb 1, 10:08 pm, Alona <> wrote:
    > On Feb 1, 9:09 pm, Tad J McClellan <> wrote:
    >
    >
    >
    >
    >
    > > Alona <> wrote:
    > > > We need to extract from a text a 3-digit numbers surrounded by certain
    > > > text. For example, we need to extract 199 surrounded by "MESSAGE TYPE"
    > > > and "SYSTEM/INPUT":

    >
    > > > MESSAGE TYPE 199 SYSTEM/INPUT

    >
    > >    my $num = substr( $_, index($_, 'SYSTEM/INPUT')-4, 3);

    >
    > > > What would be Perl regular expression for this?

    >
    > > Look Ma! No regular expression at all!

    >
    > > :)

    >
    > > --
    > > Tad McClellan
    > > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

    >
    > Thank you all. Please notice that we are searching for 199 in a
    > certain context. We are not interested in finding "MESSAGE TYPE" and
    > "SYSTEM/INPUT". We are only interested in 199, but the match should
    > only pick 199's surrounded in the text by MESSAGE TYPE adn SYSTEM/
    > INPUT.
    >
    > Thanks,
    > Alona- Hide quoted text -
    >
    > - Show quoted text -


    Also, we are not interested in Perl per se, but in perl regular
    expression rules :)
    Alona, Feb 2, 2008
    #7
  8. Alona

    Uri Guttman Guest

    >>>>> "A" == Alona <> writes:

    A> On Feb 1, 10:08 pm, Alona <> wrote:
    >> On Feb 1, 9:09 pm, Tad J McClellan <> wrote:
    >>
    >>
    >>
    >>
    >>
    >> > Alona <> wrote:
    >> > > We need to extract from a text a 3-digit numbers surrounded by certain
    >> > > text. For example, we need to extract 199 surrounded by "MESSAGE TYPE"
    >> > > and "SYSTEM/INPUT":

    >>
    >> > > MESSAGE TYPE 199 SYSTEM/INPUT

    >>
    >> >    my $num = substr( $_, index($_, 'SYSTEM/INPUT')-4, 3);

    >>
    >> > > What would be Perl regular expression for this?

    >>
    >> > Look Ma! No regular expression at all!

    >>
    >> > :)

    >>
    >> > --
    >> > Tad McClellan
    >> > email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"

    >>
    >> Thank you all. Please notice that we are searching for 199 in a
    >> certain context. We are not interested in finding "MESSAGE TYPE" and
    >> "SYSTEM/INPUT". We are only interested in 199, but the match should
    >> only pick 199's surrounded in the text by MESSAGE TYPE adn SYSTEM/
    >> INPUT.
    >>
    >> Thanks,
    >> Alona- Hide quoted text -
    >>
    >> - Show quoted text -


    A> Also, we are not interested in Perl per se, but in perl regular
    A> expression rules :)

    then ask elsewhere as this newsgroup is about perl. note that most perl
    compatible regular expressions engines aren't perl nor compatible.

    :-(

    uri

    --
    Uri Guttman ------ -------- http://www.sysarch.com --
    ----- Perl Architecture, Development, Training, Support, Code Review ------
    ----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
    Uri Guttman, Feb 2, 2008
    #8
  9. Alona <> wrote in
    news::

    > On Feb 1, 10:08 pm, Alona <> wrote:
    >> On Feb 1, 9:09 pm, Tad J McClellan <> wrote:
    >>


    >> > --


    Don't quote sigs.

    >> Thank you all. Please notice that we are searching for 199 in a
    >> certain context. We are not interested in finding "MESSAGE TYPE" and
    >> "SYSTEM/INPUT". We are only interested in 199, but the match should
    >> only pick 199's surrounded in the text by MESSAGE TYPE adn SYSTEM/
    >> INPUT.


    Please notice that we are not interested in reading the documentation to
    you. We are only interested in discussing questions where the poster has
    demonstrated that s/he has put some effort into solving the problem (one
    way to demonstrate goodwill is to read and follow the posting guidelines
    for this group).

    > Also, we are not interested in Perl per se, but in perl regular
    > expression rules :)


    OK, before I thought you were using 'we' in a cooperative sense. Now,
    you are freaking me out. Who is 'we'? 'cause in this group we are
    definitely only interested in Perl regular expression rules.

    Sinan


    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)
    clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
    A. Sinan Unur, Feb 2, 2008
    #9
    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. Dustin D.
    Replies:
    1
    Views:
    11,148
  2. RN
    Replies:
    0
    Views:
    2,541
  3. Jay Douglas
    Replies:
    0
    Views:
    594
    Jay Douglas
    Aug 15, 2003
  4. codecraig

    Regular Expressions - Python vs Perl

    codecraig, Apr 21, 2005, in forum: Python
    Replies:
    30
    Views:
    5,067
    Ilpo =?iso-8859-1?Q?Nyyss=F6nen?=
    Apr 26, 2005
  5. Noman Shapiro
    Replies:
    0
    Views:
    222
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page