Perl regular expressions

A

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
 
J

J. Gleixner

Alona said:
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?
 
M

Martijn Lievaart

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
 
H

Henry Law

Alona said:
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.
 
T

Tad J McClellan

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!

:)
 
A

Alona

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


Look Ma! No regular expression at all!

:)



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
 
A

Alona

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 :)
 
U

Uri Guttman

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
 
A

A. Sinan Unur

Don't quote sigs.

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top