in reply to Regex: What does ?k: mean?

If your goal at looking through the source is to discover what regexp the module will use for a certain type of match, this is the trick I use:

perl -MRegexp::Common=RE_ALL -E 'say $RE{num}{real}' (?:(?i)(?:[-+]?)(?:(?=[.]?[0123456789])(?:[0123456789]*)(?:(?:[.])(?:[ +0123456789]{0,}))?)(?:(?:[E])(?:(?:[-+]?)(?:[0123456789]+))|))

Of course there are many other reasons for reading the source. I've just found this shortcut useful when I want to try to understand the behavior of the patterns that are being used, or when an expression's behavior is almost but not quite what I need.


Dave

Replies are listed 'Best First'.
Re^2: Regex: What does ?k: mean?
by stevieb (Canon) on Feb 24, 2017 at 23:57 UTC

      Regexp::Common isn't really a go-to for debugging. I guess what I meant to convey was that if I have a Regexp::Common call that isn't matching as I expected and want to see what the pattern looks like, that's an easy way to dump it (diving into the source can be opaque if all you want is to see what the pattern looks like).

      For debugging patterns, I really like Regexp::Debugger. It allows you to step through the match and watch what's happening.

      You are correct that YAPE::Regex::Explain is outdated. The main problem is that the last time I checked, it stopped being developed during Perl 5.6's reign, and consequently doesn't know about features that were added to Perl after 5.6. Since Perl 5.6 is now 14 years in the past, it would seem that YAPE::Regex::Explain has been left behind. In fact, after 2001 nothing new happened to the module until 2010, and that flurry of activity (two releases) was just for bugfixes and documentation enhancements. One of the doc enhancements was to explicitly state that only regexes using constructs that were in 5.6 are supported. It's useful to those starting out trying to learn regexp basics, but it doesn't take long to discover newer constructs that fool it.


      Dave

        Thank you for this very informative feedback. I hadn't even heard about Regexp::Debugger before. I will pursue.