Quote from PHP Manual:
A back reference matches whatever actually matched the capturing
subpattern in the current subject string, rather than
anything matching the subpattern itself. So the pattern
(sens|respons)e and \1ibility
matches "sense and sensibility" and "response and responsibility" ,
but not "sense and responsibility" .
Is there a way to have a backreference matching anything matching the
subpattern itself? So that one could get "sense and responsibility" as in
the above example?
I'm trying to find a way to express this:
"/^(A)\?(B(?:\.B) *)\.(C)$/", where A, B and C are pattern like [^?.] (but
more complex, especially B)
but writing B just once, not twice. I thought backreferences were a good
idea to solve this, but as they match only the actual "result" of the
subpattern in question, this would not work here.
Any solution?
Thomas
A back reference matches whatever actually matched the capturing
subpattern in the current subject string, rather than
anything matching the subpattern itself. So the pattern
(sens|respons)e and \1ibility
matches "sense and sensibility" and "response and responsibility" ,
but not "sense and responsibility" .
Is there a way to have a backreference matching anything matching the
subpattern itself? So that one could get "sense and responsibility" as in
the above example?
I'm trying to find a way to express this:
"/^(A)\?(B(?:\.B) *)\.(C)$/", where A, B and C are pattern like [^?.] (but
more complex, especially B)
but writing B just once, not twice. I thought backreferences were a good
idea to solve this, but as they match only the actual "result" of the
subpattern in question, this would not work here.
Any solution?
Thomas
Comment