The solution is to wrap the backreference in ${}
.
$out = preg_replace( '/([aeiou])/', '${1}8', $in);
which will output a8bcde8fghi8j
See the manual on this special case with backreferences.
More Related Contents:
- Is there a PHP function that can escape regex patterns before they are applied?
- What literal characters should be escaped in a regex?
- PHP: Escape RegEx pattern to prevent being applied?
- Slice an url with regex – php [closed]
- How to extract img src, title and alt from html using php? [duplicate]
- Matching Unicode letter characters in PCRE/PHP
- PHP Regex to get youtube video ID?
- Remove multiple whitespaces
- Variable-length lookbehind-assertion alternatives for regular expressions
- PHP Regular expression to match keyword outside HTML tag
- Replace multiple newlines, tabs, and spaces [duplicate]
- How to check if string is a valid XML element name?
- PHP Regex to check date is in YYYY-MM-DD format
- Need a good regex to convert URLs to links but leave existing links alone
- Escape string to use in mail()
- file_get_contents not working?
- Validating Crontab Entries with PHP
- PHP regular expression – filter number only
- Unknown modifier ‘/’ error in PHP [duplicate]
- ffmpeg Progress Bar – Encoding Percentage in PHP
- Find JSON strings in a string
- laravel trailing Slashes redirect to localhost
- How to find a whole word in a string in PHP without accidental matches?
- How to remove square brackets and anything between them with a regex?
- Regex for names with special characters (Unicode)
- How to get all captures of subgroup matches with preg_match_all()? [duplicate]
- How to replace all XHTML/HTML line breaks () with new lines?
- How can I validate regex?
- How to remove all numbers from string?
- Regular expression preg_quote symbols are not detected