• Login
Community
  • Login

Why is this an invalid expression only in some files?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 6 Posters 1.6k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ?
    A Former User
    last edited by A Former User Oct 28, 2023, 2:48 AM Oct 28, 2023, 2:37 AM

    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++.

    ? C A M 4 Replies Last reply Oct 28, 2023, 2:48 AM Reply Quote 0
    • ?
      A Former User
      last edited by A Former User Oct 28, 2023, 2:48 AM Oct 28, 2023, 2:47 AM

      This post is deleted!
      1 Reply Last reply Reply Quote 0
      • ?
        A Former User @A Former User
        last edited by Oct 28, 2023, 2:48 AM

        I found the error. Any ideas how to fix this?

        452665d9-a436-43d2-9599-74b0ea0af2cc-image.png

        T 1 Reply Last reply Oct 29, 2023, 9:10 PM Reply Quote 0
        • C
          Coises @A Former User
          last edited by Oct 28, 2023, 4:02 AM

          @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?

          1 Reply Last reply Reply Quote 1
          • A
            Alan Kilborn @A Former User
            last edited by Oct 28, 2023, 10:46 AM

            @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.

            1 Reply Last reply Reply Quote 3
            • M
              mkupper @A Former User
              last edited by Oct 28, 2023, 5:58 PM

              @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.

              P 1 Reply Last reply Oct 28, 2023, 6:11 PM Reply Quote 1
              • P
                PeterJones @mkupper
                last edited by Oct 28, 2023, 6:11 PM

                @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 Read Before Posting
                • Template for Search/Replace Questions
                • Formatting Forum Posts
                • Notepad++ Online User Manual: Searching/Regex
                • FAQ: Where to find other regular expressions (regex) documentation
                1 Reply Last reply Reply Quote 2
                • T
                  Terry R @A Former User
                  last edited by Terry R Oct 29, 2023, 9:18 PM Oct 29, 2023, 9:10 PM

                  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

                  1 Reply Last reply Reply Quote 0
                  • P PeterJones locked this topic on Oct 29, 2023, 9:25 PM
                  8 out of 8
                  • First post
                    8/8
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors