question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

regex sub match math

See original GitHub issue
Test 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:open
  • Created 8 years ago
  • Reactions:26
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
NonsenseInccommented, Sep 18, 2016

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} result 98 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('')} result 89 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.

5reactions
renehamburgercommented, Sep 11, 2020

There has been a response to @rakkarage’s StackOverflow question by now: this can be achieved by the Super Replace VS Code extension:

image

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found