Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime regex replace merging replace text with capture group

Pretty simple problem just never encountered it before.

Say I'm replacing address information in a set of test data I have with different values. Simple stuff except that in one case I have a capture group that is to be followed directly after by a number. e.g.

Regex - \d*(/?)\d (.*) Text -  123 Main Street [should become] 72 Main Street         1/3 Main Street [should become] 7/2 Main Street Replace - 7$1B $2  <- works fine           7$12 $2  <- tries to replace with group $12 rather than $1 

Anyone know how to define these as separate without introducing any whitespace or other characters?

like image 744
Michael Allen Avatar asked Jan 16 '13 15:01

Michael Allen


People also ask

Can I use regex in replace?

How to use RegEx with . replace in JavaScript. To use RegEx, the first argument of replace will be replaced with regex syntax, for example /regex/ . This syntax serves as a pattern where any parts of the string that match it will be replaced with the new substring.

What is a capturing group regex?

Capturing groups are a way to treat multiple characters as a single unit. They are created by placing the characters to be grouped inside a set of parentheses. For example, the regular expression (dog) creates a single group containing the letters "d" "o" and "g" .

How do I find and replace in Sublime Text?

To use Find and Replace in Sublime Text 3, you can either click “Find” in the top-bar, then select “Replace” from the list, or you can press the keyboard shortcut Ctrl+H – the same way it works in, for example, Microsoft Office Word.


1 Answers

You can try other substitutions like ${1} instead of $1

Substitutions in Regular Expressions should help you..

like image 82
Anirudha Avatar answered Oct 10 '22 23:10

Anirudha