Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Regex backreference without capture (?&NAME) NamedCapture

by beech (Parson)
on Mar 05, 2019 at 03:36 UTC ( #1230882=note: print w/replies, xml ) Need Help??

in reply to Regex backreference without capture


? So you want  @x = qw( first third ) ;

This "works"

dd( 'bogus firstblahjokeblahthird bogus' =~ m/ (first) (?&patblah) .*? (?&patblah) (third) (?(DEFINE) (?<patblah>blah) ) /sx ); __END__ ("first", "third", undef)

The undef comes from the named capture  (?<patblah>blah) which takes up slot $3 in this pattern, which is why (?(DEFINE) is placed at the end

Replies are listed 'Best First'.
Re^2: Regex backreference without capture (?&NAME) NamedCapture
by QM (Parson) on Mar 05, 2019 at 10:33 UTC

    But does this do backreferences? I see it matches the same pattern, but that's not the same as a backreference.

    But thanks, that makes me think about the problem differently.

    Edited to add:
    I'm considering using named capture groups, where there's a need to have a well-defined return value. Which is something PCRE has, and some people (!) can't live without, apparently.

    Quantum Mechanics: The dreams stuff is made of

Re^2: Regex backreference without capture (?&NAME) NamedCapture
by rsFalse (Hermit) on Mar 05, 2019 at 12:34 UTC
    E.g. the input is "bogus firstblAHj?keblOWthird bogus", and pattern is 'bl..', then it matches both, but OP would like to match only the same :)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1230882]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2021-10-21 19:25 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (83 votes). Check out past polls.