Find:Invalid Regular Expression may be related to pipeline symbol search issue
-
.147.~KWH.01142025.|.147.~KWH.01152025120000AM.
The above expression was working fine before today it throws error “Find:Invalid Regular Expression”
please help me to resolve this issue
if i modify the search like .147.~KWH.01142025.|.* then its working fine
-
What is rendered in the Forum post is not what is shown in your screenshot. If you place a ` before and after the regular expression when posting, then it will render as red. Using moderator powers to look at your post, I think the original expression was
.*147.*~KWH.*01142025.*|.*147.*~KWH.*01152025120000AM.*
(which you can render in red to prevent the forum from mangling using`.*147.*~KWH.*01142025.*|.*147.*~KWH.*01152025120000AM.*`
instead of formatting as**blah**
which makes it bold, but allows the forum to interpret the characters inside as formatting characters instead of literal text )Your “modify the search” appears to be
.*147.*~KWH.*01142025.*|.*
When I run the
.*147.*~KWH.*01142025.*|.*147.*~KWH.*01152025120000AM.*
search that I extracted on a dummy file (whatever small file I happened to have open, or in a blank file), it doesn’t give an error. Which means that it’s probably that you’ve got a big (or “big-ish”) file which has lots of potential matches, but your greedy.*
might be causing too much backtracking in the file where it’s not working for you. If you hover your mouse cursor over the white “speech bubble...
” , it will give you more details on the error it’s seeing, but I expect it to tell you something like “it matches too much” or “too complex” or something (I forget the exact phrasing, and haven’t been able to recreate the error with the data I am running against.)To me, the two terms on each side of the
|
OR symbol look almost identical, so maybe you want to reduce the scope of the OR. I would try simplifying the expression to.*147.*~KWH.*(?:01142025|01152025120000AM).*
– which makes the alternation only choose between the01142025
and the01152025120000AM
, instead of making it backtrack as far as having the whole expression in the alternation: that might give it more of a chance of working on your new file.It might also help to tell it to “make the wildcards as small as possible (ie, non-greedy)” by using
.*?
anyplace you currently have.*
– “non-greedy” says “if I can get away with matching fewer characters, do so”, which might reduce the amount of backtracking (which again might make it work on your current file)But to reiterate, there’s nothing inherently wrong with your regex, so the error message is really there to tell you that the amount of backtracking it has to try for your particular data exceeds memory/complexity limits.
-
@PeterJones Thanks for quick reply and suggestion. Here is the exact when hover on speech bubble, please refer screenshot
Yes the search will be looking at 46 different files with each file consist of 500 lines. I will try your other options suggested by you today and reply. Thanks again. The original text is
.*147.*~KWH.*01142025.*|.*147.*~KWH.*01152025120000AM.*
-
To expand on @PeterJones ’ remark about reducing backtracking:
It is usually a bad idea to have multiple overlapping instances of
.*
in a regex. If you have something like.*foo.*bar.*baz
, the regex engine may spend time proportional to the cube of the length of the string (because of three overlapping.*
) on certain inputs.Usually you can change
.*
to something more specific, which will obviously depend on your use case.I guess I should add the disclaimer that the regex
(?-s).*\n.*
does not have multiple overlapping.*
because the(?-s)
ensures that the first.*
cannot consume the\n
. -
@Mark-Olson Thanks
@PeterJones it worked for the below search text with multiple files. Thanks.*147.*~KWH.*(?:02272025)|(?:02282025120000AM)