Search with content exclusion
-
@astrosofista said in Search with content exclusion:
Remove the quote from my regex if not needed.
At which point, doesn’t it become the same as MY regex? ;-)
-
Gentlemen,
Thank you very much, RESULTVALUE=(?!0) did the trick.
Sorry if I confused you - I was even more confused.
This is definitely very powerful and useful (and tricky). -
BTW - would it be impertinent from me to ask WHY/HOW this works?
I am trying to decipher (?!0) and - admittedly - don’t understand what it actually stands for.
Interestingly, I changed one of the lines to:
RESULTVALUE=090 and now the search doesn’t find it, I suspect because it starts with a 0. -
@Peter-Cohen said in Search with content exclusion:
would it be impertinent from me to ask WHY/HOW this works?
Of course not.
The construct
(?!
…)
is a negative lookahead assertion.
It means that at the current position, for there to be a composite match, whatever...
is, cannot be a match for the data (or the overall match fails).Traditionally, in computer science,
!
means “not”.So in an Englishy way, the expression
RESULTVALUE=(?!0)
means:match
RESULTVALUE=
literally, and then insist that the next character is not0
for a match to be possible.But the way
(?!0)
is used here, it precludes090
from matching (the search stops trying to match at the first 0).If something is unclear, post again.
You can find many more details about the concepts begun here, in THIS thread.
-
Hello @Alan-Kilborn - going through a crash course here.
BTW - I used to be a computer programmer in a previous life, but this, definitely, is new territory for me :-|
I will definitely have to read up on this - thanks for the link. -
@Peter-Cohen said in Search with content exclusion:
RESULTVALUE=090 and now the search doesn’t find it, I suspect because it starts with a 0.
You got it, that’s correct.
However that doesn’t mean that you cannot match a number that starts with a 0. The following regex will match
RESULTVALUE=090
but notRESULTVALUE=0
orRESULTVALUE="
, that is, whenRESULTVALUE=
is followed by any other symbol than a number:RESULTVALUE=(?!0\D)(?=\d)
Hope this helps.
-
Holy cow - let me play with this - thanks.
-
Hi, @peter-cohen, @astrosofista, @alan-kilborn and All,
Let’s imagine that we want to search for any integer or floating decimal number, different of any zero syntax, when it follows the
RESULTVALUE=
string, with this exact case. Then a possible regex, expressed with the free-spacing mode ((?x)
) could be :(?x-i) RESULTVALUE= \K [+-]? ( (?! 0 \. 0? \D | 0 [^\d.] ) \d+ ( \. \d* )? | \. (?! 0 \D ) \d+ )
- Paste the text, below, in a N++ new tab
RESULTVALUE= No ResultValue= No RESULTVALUE=. No ResultValue=. No . No RESULTVALUE=, No ResultValue=, No , No RESULTVALUE=ABC No ResultValue=ABC No ABC No RESULTVALUE=0 No ResultValue=0 No 0 No RESULTVALUE=-0 No ResultValue=-0 No -0 No RESULTVALUE=+0 No ResultValue=+0 No +0 No RESULTVALUE=.0 No ResultValue=.0 No .0 No RESULTVALUE=-.0 No ResultValue=-.0 No -.0 No RESULTVALUE=+.0 No ResultValue=+.0 No +.0 No RESULTVALUE=0. No ResultValue=0. No 0. No RESULTVALUE=+0. No ResultValue=+0. No +0. No RESULTVALUE=-0. No ResultValue=-0. No -0. No RESULTVALUE=0.0 No ResultValue=0.0 No 0.0 No RESULTVALUE=+0.0 No ResultValue=+0.0 No +0.0 No RESULTVALUE=-0.0 No ResultValue=-0.0 No -0.0 No RESULTVALUE=0.00120 Yes ResultValue=0.00120 No / Yes 0.00120 No RESULTVALUE=0.00123 Yes ResultValue=0.00123 No / Yes 0.00123 No RESULTVALUE=0.12300 Yes ResultValue=0.12300 No / Yes 0.12300 No RESULTVALUE=0.42 Yes ResultValue=0.42 No / Yes 0.42 No RESULTVALUE=.71 Yes ResultValue=.71 No / Yes .71 No RESULTVALUE=2 Yes ResultValue=2 No / Yes 2 No RESULTVALUE=5. Yes ResultValue=5. No / Yes 5. No RESULTVALUE=6.8 Yes ResultValue=6.8 No / Yes 6.8 No RESULTVALUE=007.1 Yes ResultValue=007.1 No / Yes 007.1 No RESULTVALUE=091 Yes ResultValue=091 No / Yes 091 No RESULTVALUE=+0.00120 Yes ResultValue=+0.00120 No / Yes +0.00120 No RESULTVALUE=+0.00123 Yes ResultValue=+0.00123 No / Yes +0.00123 No RESULTVALUE=+0.12300 Yes ResultValue=+0.12300 No / Yes +0.12300 No RESULTVALUE=+0.42 Yes ResultValue=+0.42 No / Yes +0.42 No RESULTVALUE=+.71 Yes ResultValue=+.71 No / Yes +.71 No RESULTVALUE=+2 Yes ResultValue=+2 No / Yes +2 No RESULTVALUE=+5. Yes ResultValue=+5. No / Yes +5. No RESULTVALUE=+6.8 Yes ResultValue=+6.8 No / Yes +6.8 No RESULTVALUE=+007.1 Yes ResultValue=+007.1 No / Yes +007.1 No RESULTVALUE=+091 Yes ResultValue=+091 No / Yes +091 No RESULTVALUE=-0.00120 Yes ResultValue=-0.00120 No / Yes -0.00120 No RESULTVALUE=-0.00123 Yes ResultValue=-0.00123 No / Yes -0.00123 No RESULTVALUE=-0.12300 Yes ResultValue=-0.12300 No / Yes -0.12300 No RESULTVALUE=-0.42 Yes ResultValue=-0.42 No / Yes -0.42 No RESULTVALUE=-.71 Yes ResultValue=-.71 No / Yes -.71 No RESULTVALUE=-2 Yes ResultValue=-2 No / Yes -2 No RESULTVALUE=-5. Yes ResultValue=-5. No / Yes -5. No RESULTVALUE=-6.8 Yes ResultValue=-6.8 No / Yes -6.8 No RESULTVALUE=-007.1 Yes ResultValue=-007.1 No / Yes -007.1 No RESULTVALUE=-091 Yes ResultValue=-091 No / Yes -091 No
-
Open the Mark dialog (
Ctrl + M
)-
SEARCH
(?-i)RESULTVALUE=\K[+-]?((?!0\.0?\D|0[^\d.])\d+(\.\d*)?|\.(?!0\D)\d+)
-
Tick the
Purge for each search
option -
Tick the
Wrap around
option -
Select the
Regular expression
search mode -
Click on the
Mark All
button
-
=> Only numbers, located after the
RESULTVALUE=
string, with this case, and strictly different from0
, should be highlighted inred
Now, if you modify the regex as
(?i)RESULTVALUE=\K[+-]?((?!0\.0?\D|0[^\d.])\d+(\.\d*)?|\.(?!0\D)\d+)
, the numbers, located after the stringResultValue=
are also highlighted !
Peter, this example is simply provided to show the powerful of regular expressions. Of course, you cannot fully understand that example, by now. Just execute the regexes to get the results and, from the @alan-kilborn’s link, try to learn the basic regex features !
Best Regards,
guy038
-
Good afternoon @Folks,
I am off to regex school, although, admittedly, these last expressions do make my head spin @Exorcist :-) -
@guy038
So i’m using this one actually:(?-i)ShaderMillDataHash" value="\K[±]?((?!0.0?\D|0[^\d.])\d+(.\d*)?|.(?!0\D)\d+)
like all values behind ShaderMillDataHash except 0:
ShaderMillDataHash" value="But i need to find another value in the same files.
Two generally to split the search results.
All search results with UBERSHADER.SHADER.BIN in the files + the regex from above
And all search results with SHADERMILLUBER.SHADER.BIN + regex from aboveI tried
(?-i)(UBERSHADER.SHADER.BIN|ShaderMillDataHash" value=")\K[±]?((?!0.0?\D|0[^\d.])\d+(.\d*)?|.(?!0\D)\d+)(?-i)SHADERMILLUBER.SHADER.BIN|ShaderMillDataHash" value="\K[±]?((?!0.0?\D|0[^\d.])\d+(.\d*)?|.(?!0\D)\d+)
and it doesnt even use the first search parameter *SHADER.BIN
So how do i do this?
-
Hello, @beatbullz and All,
So, after more than three years, and with an other user-name, you’re asking me for some modifications regarding my old provided regex. Your approach is very unusual ;-))
Anyway, I’ll try to help you !
First, I slightly improved my previous regex to this syntax, using the
free-spacing
mode(?x)
:SEARCH / MARK
(?x-i) RESULTVALUE = \K [+-]? (?: (?! 0+ ( \. 0* )? [^\d.] ) \d+ ( \. \d* )? | \. (?! 0+ \D ) \d+ )
Thus, in order to find, independently, the lines containing the string :
ShaderMillDataHash" value="
Or
SHADERMILLUBER.SHADER.BIN=
Or
UBERSHADER.SHADER.BIN=
Use the regex A , B or C, below :
Regex A :
(?-i)ShaderMillDataHash" value="\K[+-]?(?:(?!0+(\.0*)?[^\d.])\d+(\.\d*)?|\.(?!0+\D)\d+)
Regex B :
(?-i)SHADERMILLUBER.SHADER.BIN=\K[+-]?(?:(?!0+(\.0*)?[^\d.])\d+(\.\d*)?|\.(?!0+\D)\d+)
Regex C :
(?-i)UBERSHADER.SHADER.BIN=\K[+-]?(?:(?!0+(\.0*)?[^\d.])\d+(\.\d*)?|\.(?!0+\D)\d+)
Now, if you prefer to search for all the lines, at the same time, use the regex D below :
Regex D :
(?-i)(?:ShaderMillDataHash" value="|SHADERMILLUBER.SHADER.BIN=|UBERSHADER.SHADER.BIN=)\K[+-]?(?:(?!0+(\.0*)?[^\d.])\d+(\.\d*)?|\.(?!0+\D)\d+)
You can test all these regexes against the text below :
FORBIDEN cases : ShaderMillDataHash" value=" No SHADERMILLUBER.SHADER.BIN= No UBERSHADER.SHADER.BIN= No ShaderMillDataHash" value=". No SHADERMILLUBER.SHADER.BIN=. No UBERSHADER.SHADER.BIN=. No ShaderMillDataHash" value=", No SHADERMILLUBER.SHADER.BIN=, No UBERSHADER.SHADER.BIN=, No ShaderMillDataHash" value="ABC No SHADERMILLUBER.SHADER.BIN=ABC No UBERSHADER.SHADER.BIN=ABC No ShaderMillDataHash" value="0A123 No SHADERMILLUBER.SHADER.BIN=0A123 No UBERSHADER.SHADER.BIN=0A123 No ShaderMillDataHash" value="0000Z123 No SHADERMILLUBER.SHADER.BIN=0000Z123 No UBERSHADER.SHADER.BIN=0000Z123 No ShaderMillDataHash" value="0.Z123 No SHADERMILLUBER.SHADER.BIN=0.Z123 No UBERSHADER.SHADER.BIN=0.Z123 No ShaderMillDataHash" value="0.ABC123 No SHADERMILLUBER.SHADER.BIN=0.ABC123 No UBERSHADER.SHADER.BIN=0.ABC123 No ShaderMillDataHash" value="000.DEF1 No SHADERMILLUBER.SHADER.BIN=000.DEF1 No UBERSHADER.SHADER.BIN=000.DEF1 No ShaderMillDataHash" value="0 No SHADERMILLUBER.SHADER.BIN=0 No UBERSHADER.SHADER.BIN=0 No ShaderMillDataHash" value=".0 No SHADERMILLUBER.SHADER.BIN=.0 No UBERSHADER.SHADER.BIN=.0 No ShaderMillDataHash" value="0. No SHADERMILLUBER.SHADER.BIN=0. No UBERSHADER.SHADER.BIN=0. No ShaderMillDataHash" value="0.0 No SHADERMILLUBER.SHADER.BIN=0.0 No UBERSHADER.SHADER.BIN=0.0 No ShaderMillDataHash" value="00000 No SHADERMILLUBER.SHADER.BIN=00000 No UBERSHADER.SHADER.BIN=00000 No ShaderMillDataHash" value="0.000 No SHADERMILLUBER.SHADER.BIN=0.000 No UBERSHADER.SHADER.BIN=0.000 No ShaderMillDataHash" value="00.000 No SHADERMILLUBER.SHADER.BIN=00.000 No UBERSHADER.SHADER.BIN=00.000 No ShaderMillDataHash" value="0. No SHADERMILLUBER.SHADER.BIN=0. No UBERSHADER.SHADER.BIN=0. No ShaderMillDataHash" value="00. No SHADERMILLUBER.SHADER.BIN=00. No UBERSHADER.SHADER.BIN=00. No ShaderMillDataHash" value=".000 No SHADERMILLUBER.SHADER.BIN=.000 No UBERSHADER.SHADER.BIN=.000 No ALLOWED cases : ShaderMillDataHash" value="0.00120 Yes SHADERMILLUBER.SHADER.BIN=0.00120 Yes UBERSHADER.SHADER.BIN=0.00120 Yes ShaderMillDataHash" value="0.00123 Yes SHADERMILLUBER.SHADER.BIN=0.00123 Yes UBERSHADER.SHADER.BIN=0.00123 Yes ShaderMillDataHash" value="0.12300 Yes SHADERMILLUBER.SHADER.BIN=0.12300 Yes UBERSHADER.SHADER.BIN=0.12300 Yes ShaderMillDataHash" value="0.42 Yes SHADERMILLUBER.SHADER.BIN=0.42 Yes UBERSHADER.SHADER.BIN=0.42 Yes ShaderMillDataHash" value=".71 Yes SHADERMILLUBER.SHADER.BIN=.71 Yes UBERSHADER.SHADER.BIN=.71 Yes ShaderMillDataHash" value=".00954 Yes SHADERMILLUBER.SHADER.BIN=.00954 Yes UBERSHADER.SHADER.BIN=.00954 Yes ShaderMillDataHash" value="2 Yes SHADERMILLUBER.SHADER.BIN=2 Yes UBERSHADER.SHADER.BIN=2 Yes ShaderMillDataHash" value="5. Yes SHADERMILLUBER.SHADER.BIN=5. Yes UBERSHADER.SHADER.BIN=5. Yes ShaderMillDataHash" value="6.8 Yes SHADERMILLUBER.SHADER.BIN=6.8 Yes UBERSHADER.SHADER.BIN=6.8 Yes ShaderMillDataHash" value="007.1 Yes SHADERMILLUBER.SHADER.BIN=007.1 Yes UBERSHADER.SHADER.BIN=007.1 Yes ShaderMillDataHash" value="091 Yes SHADERMILLUBER.SHADER.BIN=091 Yes UBERSHADER.SHADER.BIN=091 Yes ShaderMillDataHash" value="8000 Yes SHADERMILLUBER.SHADER.BIN=8000 Yes UBERSHADER.SHADER.BIN=8000 Yes ShaderMillDataHash" value="9.000 Yes SHADERMILLUBER.SHADER.BIN=9.000 Yes UBERSHADER.SHADER.BIN=9.000 Yes ShaderMillDataHash" value="0.756000 Yes SHADERMILLUBER.SHADER.BIN=0.756000 Yes UBERSHADER.SHADER.BIN=0.756000 Yes
Best Regards,
guy038
-
@guy038 Haha, well this was really a bit unusual.
Big big thanks for the help, it was exactly what i needed!
Best wishes!