I'm trying to create a regex expression for use with Notepad++ to look for a specific character anywhere in the line but not capture it while still capturing what I want to find later in the string.
A sample of what I'm looking at is this:
GroundFogIntensityRange: [0.03, 0.08]
Stamps:
- CraterLava_2, 0.1
- CraterLava_3_BM, 0.8
Decorations:
- [Snakeweed, 0.003]
- [RockResourceNeodymium, 0.001, Free]
- [RockResourceCopper, 0.0002, Free]
- [RockResourceIron, 0.00025, Free]
- [RockResourceCopper, 0.001, Free]
which is is a configuration file for an Empyrion dynamic planet configuration.
The goal is to be able to find and put my cursor in an easy position to edit the decimals in the decoration lines. My initial attempt was to eliminate any line that had a ':' character in it.
(?<!\:)-\s\[.*,\s0\.
which worked previously when trying to eliminate the beginning of a section when spacing out block elements. This, however, was a fail because this only looks for whether or not the character exists immediately before the match. It skips the space after the ':' but continues matching everything else.
I'm trying to get it to look for the bad character anywhere in the string, not just immediately preceding the match I'm looking for. I've been scouring the web for a repeating lookback and have found zero results for anyone trying to do this. I cannot believe there would be no way to skip the match if the character preceded it anywhere in the string.
Another attempt was to try and positively match, but not capture, the set '-\s[.*,\s0.' but apparently lookahead and lookback will not allow me to use multiple characters in it without failing to get anything. I either get zero matches when doing a positive lookback or, when trying to group stuff together in the lookback, it simply selects the entire match.
I could do all this likely if I wrote a program in C# to grab the string and then eleiminate parts of it until I got what I want but that would not let me then put my cursor on it in a text editor for easy manual editing would it?
Am I hitting a block in what regex searches can do or is this possible to achieve?
You can use
(?<!:)-\h*\[.*,\h\K0\.
Details:
(?<!:)
- a position that is not immediately preceded with a :
char-
- a hyphen\h*
- zero or more horizontal whitespaces\[
- a [
char.*
- zero or more chars other than line break chars, as many as possible,
- a comma\h
- a horizontal whitespace\K
- match reset operator that discards the text matched so far0\.
- 0.
text