Reputation: 123
I just learned about regex and it's still quite confusing to me.
For a start, I'm having a file in Notepad++ with 500k lines. At about line 394900 is some static content that needs to be replaced. It's not that much to do manually, but just for learning purpusses I'd like to do this via RegEx.
The lines contain the following strings while X is a RandomNumber: {x 0.xxxxx xx.xxx} Now I have to replace the second number of each line before the .xxxxx
So to make it short: {x 0.xxxxx xx.xxx} has to be replaced with {x 8.xxxxx xx.xxx} in each line.
What would be the easiest way to do this via regex?
Upvotes: 0
Views: 498
Reputation: 174696
You could use a positive lookahead based regex like below,
\d+(?=\.\d{5}\s)
Then replace the matched number with 8
. It matches the number only if it's followed by a dot then a 5 digit number and a space.
Upvotes: 0
Reputation: 72844
Using \d
to represent a digit:
Replace (\{\d )\d(\.\d{5} \d{2}\.\d{3}\})
with \18\2
(first group, then the digit 8
, followed by the second group).
If explicit quantifiers (e.g. \d{3}
) are not supported, use \d+
instead (i.e. one or more digits):
Without explicit quantifiers (for Npp version < 6):
Replace (\{\d )\d(\.\d+ \d+\.\d+\})
with \18\2
.
Upvotes: 1