Math operations in regex

using Perl:

s/.*doc=(\d+).*/"www.site.com\/headline\/".($1+100000).".article"/e;

as you've done with e flag, the right part becomes now an expression. so you have to wrap the non-capture part as strings.


That's not possible in regex. Regex only matches patterns, it doesn't do arithmetic.

The best you can do is something verbose like:

match       replace

(\d{6,})    $1
(\d{5})     1$1
(\d{4})     10$1
(\d{3})     100$1
(\d{2})     1000$1
(\d)        10000$1

Tags:

Regex