Newbie find and replace
-
I’ve read the tutorials and several of the questions from others to try and figure this out, I have gotten close by being able to find my strings but I can’t seem to get the replacement to work correctly.
Current lines:
BuildingAreaSource Character,75,Values
BuildingNumber Character,5,
BuildingUse Character,1000,Values
BusinessName Character,40,
BuyersAgencyCommission Character,10,
CancelledDate DateTime,10,
CapitalizationRate Decimal,7,I need to end up with:
BuildingAreaSource Character(75),
BuildingNumber Character(5),
BuildingUse Character(1000),
BusinessName Character(40),
BuyersAgencyCommission Character(10),
CancelledDate DateTime(10),
CapitalizationRate Decimal(7),This is what I was using:
Find what: ,[0-9]+,
Replace with: (\1),Result from this search just deletes my numerals and leaves one comma
How can I get it to put the numerals back with the ()
TIA
-
Well you have a few problems with your regex…one big one is that in the replace expression you reference a group # that doesn’t exist because you didn’t use capturing parentheses in your find expression…
Maybe try this:
Find what zone:
,(\d+),(?:Values)?$
Replace with zone:\(\1\),
Search mode: Regular expressionHere’s an explanation of how it works:
THE FIND EXPRESSION:
,(\d+),(?:Values)?$
- Match the character “,” literally
,
- Match the regex below and capture its match into backreference number 1
(\d+)
- Match the character “,” literally
,
- Match the regular expression below
(?:Values)?
- Assert position at the end of a line (at the end of the string or before a line break character) (carriage return and line feed, form feed)
$
THE REPLACE EXPRESSION:
\(\1\),
- Insert an opening parenthesis
\(
- Insert the text that was last matched by capturing group number 1
\1
- Insert a closing parenthesis
\)
- Insert the character “,” literally
,
Created with RegexBuddy
- Match the character “,” literally
-
Thank you very much!