Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2022-05-16 09:53 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (62 votes). Check out past polls.