Berkeley CSUA MOTD:Entry 38890
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/04/07 [General] UID:1000 Activity:popular
4/7     

2005/7/30-8/2 [Uncategorized] UID:38890 Activity:nil
7/30    For a regular expression like (?:(FOO)|(BAR)|(BAZ))(GARPLY) where
        exactly one of expressions FOO, BAR, or BAZ will match, is there
        a way to have only one backreference returned for the one that
        matches? That is, I'd like $1 to be for that match, and $2 to be the
        match for GARPLY. This is using preg_split (pcre on PHP). Thanks.
        \_ (FOO|BAR|BAZ)(GARPLY) --dbushong
           \_ Well, actually, I guess I didn't explain this quite right.
              Say I have something like (?:FOO|BAR|BAZ)(GARPLY),
              and FOO, BAR, and BAZ each have two sets of capturing
              parens themselves. I want those matches to be $1 and $2,
              and GARPLY to be $3.
              \_ I don't believe you can do that... but since you're trying
                 to do this with preg_split, how do you plan on capturing
                 any matches at all?  --dbushong
                 \_ There's an option for returning captured matches.