Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Regular Expressions-Finding info between semicolons

by Paladin (Vicar)
on Nov 09, 2016 at 23:25 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1175641]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-23 12:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found