PHP core technology and best practice regular expression Reverse reference
A reverse reference is used to repeat the search for text that precedes a grouping match. For example, "\1" represents the text for grouping 1 matches:
\b (\w+) \b\s+\1\b
To reverse-reference the contents of a grouped capture, you can use the previous example of "\k<word>":
\b (? <word>\w+) \b\s+\k<word>\b
"Example": Ubb Tag Code
UBB tags are used instead of HTML in forums and message boards to achieve some simple HTML effects while preventing the misuse of HTML security issues.
Finally, the UBB tag will be parsed into HTML code to allow the browser to recognize the URL tag as an example.
"[Url]1.gif[/url]"
<? PHP $str = ' [Url]1.gif[/url][url]2.gif[/url] [Url]3.gif[/url] '; $s = preg_replace ("#\[url\" (? <word>\d\.gif) \[\/url\]# "," ; Var_dump ($s);? >
PHP core technology and best practice regular expression Reverse reference