Perl regular expressions

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 [ Fr, 01 Februar 2008 22:58 ] [ ID #1922167 ]

Re: Perl regular expressions

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?
glex_no-spam [ Fr, 01 Februar 2008 23:12 ] [ ID #1922169 ]

Re: Perl regular expressions

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 [ Fr, 01 Februar 2008 23:19 ] [ ID #1922172 ]

Re: Perl regular expressions

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 [ Fr, 01 Februar 2008 23:19 ] [ ID #1922173 ]
Perl » comp.lang.perl.misc » Perl regular expressions

Vorheriges Thema: Perl on Linux and AIX
Nächstes Thema: Magic for object constructor wanted