in reply to Re^2: Help in joining these lines
in thread Help in joining these lines

Although use re 'debug'; is available, YAPE::Regex::Explain is a fair amount more detailed in its output when explaining a regex:

use warnings; use strict; use YAPE::Regex::Explain; my $re = 's/ ^\w*\K\n(?=\w*\n) | ^.*\..*\K\n(?=.*\.) //mx'; print YAPE::Regex::Explain->new($re)->explain;

Output:

The regular expression: (?-imsx:s/ ^\w*\K\n(?=\w*\n) | ^.*\..*\K\n(?=.*\.) //mx) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- s/ 's/ ' ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- \w* word characters (a-z, A-Z, 0-9, _) (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \K 'K' ---------------------------------------------------------------------- \n '\n' (newline) ---------------------------------------------------------------------- (?= look ahead to see if there is: ---------------------------------------------------------------------- \w* word characters (a-z, A-Z, 0-9, _) (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \n '\n' (newline) ---------------------------------------------------------------------- ) end of look-ahead ---------------------------------------------------------------------- ' ' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- ' ' ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- .* any character except \n (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \. '.' ---------------------------------------------------------------------- .* any character except \n (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \K 'K' ---------------------------------------------------------------------- \n '\n' (newline) ---------------------------------------------------------------------- (?= look ahead to see if there is: ---------------------------------------------------------------------- .* any character except \n (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \. '.' ---------------------------------------------------------------------- ) end of look-ahead ---------------------------------------------------------------------- //mx ' //mx' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

For the items that still may not be clear, see perlre.

Replies are listed 'Best First'.
Re^4: Help in joining these lines
by AnomalousMonk (Archbishop) on Sep 15, 2016 at 17:01 UTC
Re^4: Help in joining these lines
by kcott (Archbishop) on Sep 16, 2016 at 11:57 UTC

    I think YAPE::Regex::Explain is an excellent tool for those learning the basics. However, it does have its LIMITATIONS:

    "There is no support for regular expression syntax added after Perl version 5.6, particularly any constructs added in 5.10. ..."

    — Ken

Re^4: Help in joining these lines
by Anonymous Monk on Sep 15, 2016 at 16:13 UTC

    Explain is out of date. \K is no longer just K, but causes stuff to the left to not be included in $&.