By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,349 Members | 1,353 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,349 IT Pros & Developers. It's quick & easy.

Backreferences

P: n/a
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


Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Thomas Mlynarczyk écrivit:
(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?

You can just repeat the pattern :

(sens|respons)e and (sens|respons)ibility

--
P'tit Marcel
Jul 16 '05 #2

P: n/a
Also sprach P'tit Marcel:
(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?

You can just repeat the pattern :

(sens|respons)e and (sens|respons)ibility


Precisely what I want to avoid.

--

Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.