Reputation: 13892
I have lines like this
TEL;TYPE=CELL:343-454-1212
TEL;TYPE=CELL:34345-121212
TEL;TYPE=CELL:123456789
I need to remove dashes from them using VSCode.
So far I came with:
Search With : (TEL;TYPE=CELL:\d*)-(\d*)
Replace With : $1$2
I have to search and replace multiple times (In this case two times) to get the expected output. This is mainly because I do not know how many dashes are there.
Is there any regex which I can use to accomplish, what is being done here in single go?
Upvotes: 1
Views: 964
Reputation: 627126
Visual Studio Code search and replace in the current document feature (not the one to replace in files) supports regexps with variable-width lookbehind patterns, so you can use
(?<=TEL;TYPE=CELL:[\d-]*)-
See the regex demo. Details:
(?<=TEL;TYPE=CELL:[\d-]*)
- a position that is preceded with TEL;TYPE=CELL:
and then zero or more digits or hyphens-
- a hyphen.Upvotes: 2
Reputation: 3806
Wrap the number in parenthesis like this so you can restore it, removing the -
-([0-9])
replace with $1
Or Just repeat this find replace, till they are all removed:
Upvotes: 2
Reputation: 1775
I tried this limited solution.only for 2 or 3 dash.
Search with: (\d+)-(\d+)(?:-(\d+))?
Replace with: $1$2$3
but in the comment that said replace dashes with empty str also a good solution.
Upvotes: 2