ElectroRed has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex explanation
by Discipulus (Canon) on Sep 14, 2015 at 08:37 UTC | |
But YAPE::Regex::Explain is our friend!
L* UPDATE: as stated by wise monks below the module does not handle substitutions and in the case above produce somehow misleading output (as lib//). So better to reduce the regex to a non substituiton one and inspect the output to see where the error is (at the dot).
There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS. | [reply] [d/l] [select] |
by choroba (Cardinal) on Sep 14, 2015 at 10:45 UTC | |
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
| [reply] [d/l] |
by Discipulus (Canon) on Sep 14, 2015 at 11:04 UTC | |
L*
There are no rules, there are no thumbs.. Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS. | [reply] [d/l] |
by AnomalousMonk (Archbishop) on Sep 14, 2015 at 14:25 UTC | |
by Anonymous Monk on Sep 15, 2015 at 03:42 UTC | |
YAPE::Regex::Explain doesn't handle ... Luckily :) other regex tools, ppixregexplain.pl ... Read more... (9 kB)
| [reply] |
|
Re: Regex explanation
by hippo (Archbishop) on Sep 14, 2015 at 08:38 UTC | |
Sure. It looks for the phrase 'lib' more than 1 character after a slash. If that is found then it replaces everything up to and including the 'lib' with what was between the slash and the character before the 'lib'. The expression to be matched against (and altered) is in $lib_name. eg. if the expression were 'foo/barlib' the result would be 'ba' | [reply] [d/l] |
|
Re: Regex explanation
by Your Mother (Archbishop) on Sep 14, 2015 at 12:33 UTC | |
FWIW, it's a poorly crafted regex. It will make false matches; e.g.–
I presume it is meant to match and retain the plain lib name. This is saner but maybe not as good as it gets– $lib_name =~ s{\A.+/([^/]+)\.lib\z}{$1};I left out dot-star because you should if you can and if we know there will always be a slash before the lib (/lib) then we can assume there will always be *some* content before the slash (c.f., there is never going to be a volume:/lib dir). Lots more info: perlre. | [reply] [d/l] [select] |