Why is this an invalid expression only in some files?
-
I am using the following regular expression to do mass text replacement across various files:
[a-z,0-9]\h*[^:]+*.latest:/This works in 95% of files, however 5% of them claim it is an invalid expression and doesn’t give me any further information. This worked flawlessly up until newer versions of notepad++. What’s wrong with it with this expression?
An example of what this expression should do is change:
“url” : “ANYTEXT.ANYTEXT.latest:/path/path/.mp3”,Deleting part of it and producing:
“url” : “/path/path/.mp3”,Even *.latest:/ produces the “invalid regular expression” error on latest version of notepad++.
-
This post is deleted! -
I found the error. Any ideas how to fix this?
-
@Ben-1 said in Why is this an invalid expression only in some files?:
[a-z,0-9]\h*[^:]+*.latest:/
That is invalid; but I think you meant to type:
[a-z,0-9]\h*[^:]+\.latest:/
instead.
Why is the
\h*
there? Given your example, it looks like you’re trying to match:(?<=")[^"]+\.latest:(?=/)
Does that work for you?
-
@Ben-1
It’s really hard to tell anything from the regular expression posted, because you didn’t post it correctly.
But, it appears that the data you want to match is on a single line? If so, you probably want the
. matches newline
checkbox to be uncheckmarked – with that state it is hard to believe that you’d receive the “complexity” error message. -
@Ben-1 said in Why is this an invalid expression only in some files?:
[^:]+*.
The main culprit seems to be the
[^:]+
part of your expression. You are scanning for anything that is not a colon. In Notepad++, this will zip past the end of the line. If the region spanned by this scan becomes too large (somewhere in the thousands of lines) then you get seemingly spurious “invalid expression” errors.I am puzzled by something else in your expression is the the
*.
that’s part of[^:]+*.
in your expression. It looks invalid. What is your intent here?It would really help if you followed the advice at Template for Search/Replace Questions as what you posted creates too much guesswork among others that may want to help you. The little ``` marks in that template are important.
-
@mkupper said in Why is this an invalid expression only in some files?:
I am puzzled by something else in your expression is the the . that’s part of [^:]+. in your expression. It looks invalid. What is your intent here?
Looking at the original content of the post, it was
[a-z,0-9]\h*[^\:]+\*.latest:/
– I don’t know whether @Ben-1 added the backslash just to get the * to not cause italics in the forum, or whether it was intended as part of the regular expression (ie, looking for a literal*.latest
)…@Ben-1 , this is why we have the Template for Search/Replace Questions and Formatting Forum Posts FAQs, both of which are linked to from Please Read Before Posting, which one should read before posting. If you had spent the extra 5 minutes to read those three posts, you could have made your actual intent obvious from the first post, rather than having people trying to guess your intent for 16 hours after you posted. (I point this out for your benefit to help you craft future posts, and for future replies to this post, not because I’m angry or because you’re “in trouble”.)
----
Useful References
-
Please note that the poster’s account that started this conversation was removed. This was due to issues for new posters trying to reply to other posts, the forum’s moderators are working on a fix. Then the poster created a new (similar) account and posted another thread, with almost the same question.
That thread is located here.
Terry
-