http://qs321.pair.com?node_id=1175641


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!