regex sub match math
See original GitHub issueTest 300
Test 301
Test 302
I can use regex find to loop through these:
Test (3[0-9]*)
When I try replace with math it concatenates instead of evaluates?
Test $1-100
So, it becomes:
Test 300-100
Is it possible to evaluate instead of concatenate, so it becomes:
Test 200
It works in vim regex:
%s@Test (3[0-9]*)@\='Test '.(submatch(1)-100)@
Thanks.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:26
- Comments:17 (1 by maintainers)
Top Results From Across the Web
Regex: math and substitute strings? - Stack Overflow
I have part of a regex match expression going; I'm stuck on the part where I need to match symbols and replace them...
Read more >re — Regular expression operations — Python 3.11.1 ...
A regular expression (or RE) specifies a set of strings that matches it; the functions in this module let you check if a...
Read more >RegEx replace with math on captured numbers - Sublime Text
I would like to write a regular expression that captures a number and then make use of the captured number in the replace...
Read more >Regular Expression in Python with Examples | Set 1
Return all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in ......
Read more >Replace text using regular expression - MATLAB regexprep
'\w*\D\>' matches words that do not end with a numeric digit. \oN or \o{N}. Character of octal value N.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
why not integrate a eval operator like
${some javascript}
. Let me give an example:input
99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around, 98 bottles of beer on the wall.
search(\d+)
replace with${$1 - 1}
result98 bottles of beer on the wall, 98 bottles of beer. Take one down and pass it around, 97 bottles of beer on the wall.
search(\w+)
replace with${$1.split('').reverse().join('')}
result89 selttob fo reeb no eht llaw, 89 selttob fo reeb. Ekat eno nwod dna ssap ti dnuora, 79 selttob fo reeb no eht llaw.
I think that would be very useful.
There has been a response to @rakkarage’s StackOverflow question by now: this can be achieved by the Super Replace VS Code extension: