Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex.Replace: How to use $groups followed by numbers [duplicate]

Tags:

With Regex::Replace we can use $1, $2, ... to match corresponding groups. But how can I use $1 followed by number. E.g. to replace 6 with 678?

 Regex::Replace(text, "(6)", '$178'); 
like image 800
alex2k8 Avatar asked May 01 '09 12:05

alex2k8


2 Answers

You need to use the alternate syntax:

Regex::Replace(text, "(6)", "${1}78"); 
like image 79
Jeff Moser Avatar answered Sep 19 '22 15:09

Jeff Moser


It seems I can use $`

Regex::Replace(text, "(6)", '$1$`78'); 
like image 45
alex2k8 Avatar answered Sep 17 '22 15:09

alex2k8