in reply to Re^3: POD style regex for inline HTML elements
in thread POD style regex for inline HTML elements

DUDE:) http://cpansearch.perl.org/src/ABIGAIL/Regexp-Common-2013031301/Changes
Version 2013030901 Sat Mar 9 14:51:42 CET 2013 + Use (?-1) instead of (??{ }) for the recursive balanced pattern. This makes the pattern unavailable for pre-5.010 perls.

So solution is simple, on any computer you have, get the old version, print out the pattern and save it to a file

cpanm -n http://cpan.metacpan.org/authors/id/A/AB/ABIGAIL/Regexp-Common-2011121001.tar.gz

$ perl -MRegexp::Common -le " print $RE{balanced}{-parens=>'<>'} " (?^:(?^:(?:\<(?:(?>[^\<\>]+)|(??{$Regexp::Common::balanced [0]}))*\>)) +)

So to inline into above program you'd write something like

use vars qw/ $re_balanced_angles /; our $re_balanced_angles = qr{(?^:(?^:(?:\<(?:(?>[^\<\>]+)|(??{ $re_bal +anced_angles }))*\>)))}; ... m{ ### no more ## \G( $allowed )( $RE{balanced}{-parens=>'<>'} ) \G( $allowed )( $re_balanced_angles ) }gcsx and do {

Or downgrade the version of Regexp::Common you upload to your website

Replies are listed 'Best First'.
Re^5: POD style regex for inline HTML elements
by Lady_Aleena (Priest) on May 16, 2014 at 22:27 UTC

    Dear Anonymous Monk, it appears this will not work in Perl 5.8.8. The ?^ returns an error too. I will have to give up on this for now, since I can't convince my webhost to upgrade their default Perl to the minimum Regexp::Common requires. Thank you for your work, I am just sorry I can't use it.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena

      Dear Anonymous Monk, it appears this will not work in Perl 5.8.8. The ?^ returns an error too.

      Well, sorry about that, I forgot about that (5.16 is my first perl in path), thats just the way it stringifies on the newer perls, you can simply ditch the ^

      With actual 5.8.8 it stringifies as

      (?-xism:(?-xism:(?:\<(?:(?>[^\<\>]+)|(??{$Regexp::Common::balanced [0] +}))*\>)))

      So here is the updated file, test still pass, with actual 5.8.8 too :)

        Will you please tell me what I am missing after I took all of the comments out? I'm still getting an infinite loop when these are nested with the error Use of uninitialized value in numeric gt (>) at files/lib/Base/HTML/Inline.pm line 32, <DATA> line 19.

        package Base::HTML::Inline; use strict; use warnings; use Exporter qw(import); our @EXPORT_OK = qw(inline); # Written by an Anonymous Monk on PerlMonks (http://www.perlmonks.org/ +?node_id=1028699) use Test::More qw' no_plan '; use Regexp::Common qw/ balanced /; use Data::Dump qw/ dd pp /; use vars qw/ $re_balanced_angles /; sub TRACE; sub DEBUG; *TRACE = *DEBUG = sub { print STDERR @_,"\n" }; our $re_balanced_angles = qr{\<(?:(?>[^\<\>]+)|(??{ $re_balanced_angle +s }))*\>}x; our $allowed = join '|', qw[ A ABBR ACRONYM B BIG CITE CODE DFN EM I KBD Q SAMP SMALL SPAN STRONG SUB SUP TT VAR ]; sub inline { local $_ = $_[0]; my $dent = $_[1] || 0; pos = 0; my $ret = ""; inlineLOOP: while( length > pos ){ m{\G(\s+)}gcsx and do { $ret .= $1; next inlineLOOP; }; m{\G( $allowed )( $re_balanced_angles )}gcsx and do { TRACE "# $dent allowed<> { $1 ( $2 ) }"; $ret .= inline_allowed( "$1" , "$2" , $dent ); next inlineLOOP; }; m{\G([^<]+\s)}gcmx and do { TRACE "# $dent text { $1 }"; $ret .= inline_text( "$1" ); next inlineLOOP; };;; m{\G([\<\>])}gcmx and do { TRACE "## $dent error-stray<> { $1 } at pos(@{[pos]})"; last inlineLOOP; };;; m{\G(\S)}gcmx and do { TRACE "# $dent inch-forward { $1 }"; $ret .= inline_text( "$1" ); next inlineLOOP; };;; } $ret; } sub inline_allowed { my( $tag , $stuff, $dent ) = @_; $stuff = $1 if $stuff =~ m{^<(.*)>$}gs; my $ret = ""; $ret .= "<\L$tag\E" if $tag; $stuff =~ s{\|([^<>]+)$}{$ret .= " $1"; "";}gsex if defined $stuff + ; ## inline_allowed_atts($tag,$1); $ret .= ">" if $tag; if( defined $stuff and length $stuff and $stuff =~ m{[<>]}g ){ $ret .= inline( $stuff , $dent+1) ; ## recurse } else { $ret .= $stuff; } $ret .= "</\L$tag\E>" if $tag; $ret; } sub inline_text { join'',@_ } 1;
        No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
        Lady Aleena