Obtaining matched (sub)string

M

Michael T. Davis

When using m//, is it possible to obtain the (sub)string of the
target which actually matched the regex? For example, if the target is
"Get your viagra here" and the regex is "(cialis|viagra|xanax)", is there
a way to indicate that the match was "viagra"?

Thanks,
Mike
 
G

Gunnar Hjalmarsson

Michael said:
When using m//, is it possible to obtain the (sub)string of the
target which actually matched the regex? For example, if the
target is "Get your viagra here" and the regex is
"(cialis|viagra|xanax)", is there a way to indicate that the match
was "viagra"?

Err.. Yes. By examining the content of $1.

http://www.perldoc.com/perl5.8.4/pod/perlretut.html

(Are there any spam crap any longer that spells out "viagra" in
cleartext?)
 
T

Tad McClellan

Gunnar Hjalmarsson said:
(Are there any spam crap any longer that spells out "viagra" in
cleartext?)


He may be working on "normalized" words, so his code _may_ be useful.
 
M

Michael T. Davis

Tad McClellan said:
He may be working on "normalized" words, so his code _may_ be useful.

That is, in fact, what I'm doing. The case I provided was just a
simplification.

Regards,
Mike
 

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

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,404
Latest member
PerryRutt

Latest Threads

Top