Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Capturing groups where the ending is optional

by ikegami (Pope)
on Jan 14, 2018 at 23:42 UTC ( #1207242=note: print w/replies, xml ) Need Help??


in reply to Capturing groups where the ending is optional

I think you're asking for

/ ^ ( (?: (?!\Q$key\E). )* ) ( .* ) /xs

By the way, you shouldn't be using \1 and \2 in the substitution expression (as Perl told you through warnings you apparently ignored). \1 and \2 are regex atoms that instruct the regex engine to match first and second captured string respectively. It makes no sense to use them in the substitution expression. Use $1 and $2 instead.

Replies are listed 'Best First'.
Re^2: Capturing groups where the ending is optional
by cwm9 (Initiate) on Jan 14, 2018 at 23:49 UTC
    Thank you. I'll examine this code. As for the $1 vs \1, there were no warnings --- I'm only using perl from the command line in a bash script. I'm pretty much a complete perl noob. Thank you for helping.
      ... there were no warnings --- I'm only using perl from the command line .... I'm pretty much a complete perl noob.

      Perl noobs in particular should always enable warnings and strictures. One way to do this from the command line is
          perl -wMstrict -e "perl code here ..." whatever else ...
      (double-quotes for Windoze, single-quotes otherwise).


      Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2018-11-13 03:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (149 votes). Check out past polls.

    Notices?