Reputation: 1613
I'd like to have a regular expression in PHP like "/A.B./i"
but the random character following A and the random character following B should be equal.
How can I solve this?
Upvotes: 2
Views: 131
Reputation: 4118
This should work:
$regex = '/A(.)B\1/i';
The \1
referencing the captured group (.)
is called a back-reference (as @Ilmari Karonen was kind enough to remind).
Upvotes: 6