Can one line RegExReplace code do this job? How?
Add 10 to all numbers leading with "x" in the text:
Text: aa x1.2 bb x2.3 cc x45 ddd x1.2 ee x8
to: aa x11.2 bb x12.3 cc x55 ddd x11.2 ee x18
Thanks!
Regular Expression help, please.
- oldbrother
- Posts: 273
- Joined: 23 Oct 2013, 05:08
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
Re: Regular Expression help, please.
Code: Select all
Text = aa x1.2 bb x2.3 cc x45 ddd x1.2 ee x8
while pos := RegExMatch(Text, "x(\d+)", m, A_Index=1?1:pos+StrLen(m))
Text := RegExReplace(Text, "x\K\d+", m1+10,, 1, pos)
MsgBox % text
- oldbrother
- Posts: 273
- Joined: 23 Oct 2013, 05:08
Re: Regular Expression help, please.
Thank you AlphaBravo! It works perfectly!
What is the function of "K" in "x\K\d+"? I cannot find it from the help file.
What is the function of "K" in "x\K\d+"? I cannot find it from the help file.
Re: Regular Expression help, please.
https://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm wrote:The escape sequence \K is similar to a look-behind assertion because it causes any previously-matched characters to be omitted from the final matched string. For example, foo\Kbar matches "foobar" but reports that it has matched "bar".
- oldbrother
- Posts: 273
- Joined: 23 Oct 2013, 05:08
Re: Regular Expression help, please.
Thank you all! Have a great weekend!
Who is online
Users browsing this forum: iamasink, jollyjoe, Noitalommi_2, RareUserGerman and 311 guests