stefankueng / grepWin

A powerful and fast search tool using regular expressions
https://tools.stefankueng.com/grepWin.html
GNU General Public License v3.0
1.76k stars 182 forks source link

Mismatching results not as shown in RegEx test result #372

Closed Hexaae closed 1 year ago

Hexaae commented 1 year ago

no_match_Immagine 2023-01-30 200639

This is the text I used for testing in the test panel: https://hastebin.com/uracacaxik.apache Search string:(\r\n)^(?!.*(\# OSD PER-WINDOW))(?!aspect0).*$

The resulting file (upper-left open in CudaText) shows something different from what was shown in the preview (test panel).

stefankueng commented 1 year ago

don't use \r\n but only \n in the test dialog since grepWin normalizes the line endings. also check the box "dot matches newline" if you search over multiple lines

Hexaae commented 1 year ago

but I need to remove exactly all \x0d\x0a... except those lines after ^...

stefankueng commented 1 year ago

also check the box "dot matches newline" if you search over multiple lines

Hexaae commented 1 year ago

uhm... this way though it won't do what I wanted... expected results:

#
# OSD PER-WINDOW VIDEO OPTIONS
aspect0                   17:10

I'm a newbie with RegEx though :(

stefankueng commented 1 year ago

do you actually want to remove everything except the "OSD PER-WINDOW VIDEO OPTIONS" and the value, or do you want to filter that information out and create a new file with that?

The first option will get very complicated, that regex would grow to a huge monster. The second option however is easer: just search for that and use the "Capture search" feature instead. image

search string: #(?:\n|\r\n|\n\r)(# OSD PER-WINDOW VIDEO OPTIONS)((?:\n|\r\n|\n\r)#)(\n|\r\n|\n\r)(aspect0\s+[0-9.:]+) replace string: $1$2$3$4

and then use the "Capture search": image

Hexaae commented 1 year ago

Thanks for your help. Yes, wanted to preserve just the following in the final ini, removing everything else and it seems a quite complicated challenge indeed... ;)

#
# OSD PER-WINDOW VIDEO OPTIONS
#
aspect0                   17:10

Tried your search above but I got no match at all using https://paste.sh/3vzEJkJH#_IZHMlAsw7RUu8esOdmURU5g , even when selecting "Capture search": image ATM, the best solution I've found is on https://stackoverflow.com/questions/75212474/keep-only-a-few-specific-lines-inside-some-text-files-using-regex-for-mass-text , which is almost perfect but probably a bit incorrect.

stefankueng commented 1 year ago

closing this issue, because I can't start helping with regex search strings. I'm coding the tool, not supporting users with their searches, sorry.

Hexaae commented 1 year ago

I understand, and thanks for helping anyway.

Hexaae commented 1 year ago

Thinking about this bug... going back to the 1st message (and ignoring the attempt to find a better pattern-matching...) the problem was that test dialogue shows inaccurate results: processed file doesn't look like test dialogue even if I use just "\x0a" removing the \r\n thing... 🤔 Can the line ending problem you mentioned be fixed to make dialogue show the exact result? This means the test window can be misleading and inaccurate...

To show in the test dialogue the correct preview (= matches actual file after Replace) I have to use \r in front of the string: \r(\n)^(?!.*(\# OSD PER-WINDOW))(?!aspect0).*$ This will remove the CR lines too from preview, as the replacement regex string without \r does on the real file: (\n)^(?!.*(\# OSD PER-WINDOW))(?!aspect0).*$