Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

regex : finding the location multiple clustered (in parenthesis) groups

by yonatan (Novice)
on Aug 02, 2010 at 09:47 UTC ( [id://852440]=perlquestion: print w/replies, xml ) Need Help??

yonatan has asked for the wisdom of the Perl Monks concerning the following question:

hello monks,

i wish to match the "neither-nor" couples in the following text sample:

".. Neither Jack nor Peter wants to go to the party next week. Neither Jane nor her friends support the mayor. .."

suggested matching pattern is:

(\bneither\b)[^.?!;]*?(\bnor\b)

i want to get the location of BOTH the first (\bneither\b) and its following (\bnor\b).

the location information may be similar to that returned by pos(), i.e. the following character position when //g is in use.

my questions:

1. is there an elegant way to return the position of single parenthesized group?

2. -"- the position of each group out of multiple groups?

thank you!

Replies are listed 'Best First'.
Re: regex : finding the location multiple clustered (in parenthesis) groups
by BrowserUk (Patriarch) on Aug 02, 2010 at 10:15 UTC
      The link above goes to documentation for an older version of perl. This one should be up-to-date enough to include @-

      perlvar

      --
      use JAPH;
      print JAPH::asString();

      thank you. this is exactly what i needed.

      your link is outdated (applies to perl 5.6), thus lacking the definition of @- .

      i attach an updated link to perlvar documentation which holds your intended contents.

Re: regex : finding the location multiple clustered (in parenthesis) groups
by patrick.j (Acolyte) on Aug 02, 2010 at 12:02 UTC
    You Might Consider using @- (or @LAST_MATCH_START with use English)
    1. It holds exactly what you are asking for first matching Group start at $-1, first matching group end at $+1.
    2. see 1. (use something like @-1,2)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://852440]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-24 00:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found