Perl regular expressions
am 01.02.2008 22:58:10 von alona
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
Re: Perl regular expressions
am 01.02.2008 23:12:22 von glex_no-spam
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?
Re: Perl regular expressions
am 01.02.2008 23:19:23 von Martijn Lievaart
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
Re: Perl regular expressions
am 01.02.2008 23:19:35 von Henry Law
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