Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Regular Expressions-Finding info between semicolons

by Paladin (Vicar)
on Nov 09, 2016 at 23:25 UTC ( #1175641=note: print w/replies, xml ) Need Help??


in reply to Regular Expressions-Finding info between semicolons

This is a fairly common issue I see with Regex. People use . in their regexen when that's not what they actually mean.

In your example you have: /\;(.*?L.*?)\;/. You are looking for a L surrounded by a bunch of stuff that isn't semicolons, but . means "everything", not "everything except semicolons". If you want to say "everything except semicolons" in the regex, then say that: /\;([^;]*?L[^;]*?)\;/

[~]$ perl -le '$_ = ";A-B-C-D;E-F-G-H;J-K-L-M;N-P-R-S;T-W-Y-Z;"; /\;([ +^;]*?L[^;]*?)\;/; print $1;' J-K-L-M
tl;dr: Don't use . if you don't mean .

Replies are listed 'Best First'.
Re^2: Regular Expressions-Finding info between semicolons
by adrianm96 (Novice) on Nov 09, 2016 at 23:42 UTC

    Thanks for your help! Yeah I saw what was happening, I was just having trouble translating what I wanted into code to match the pattern. Thanks again!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1175641]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2019-10-18 20:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?