Community
    • Login

    Regex Search With Quotations

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 2 Posters 3.2k 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.
    • DevSrc8D
      DevSrc8
      last edited by DevSrc8

      I am trying to search a folder (20-30 text files) for a string that can contain a variety of letters in the alphabet.

      example 1:
      range(“A1”)
      search = "A

      example 2:
      range(“$I$15:$I$19”)
      search = "$A and $I

      now I want to do this for all letters so I thought it would be something to the affect of for…
      ex 1: A|B|C|D|E|F|G|H|I|JK|L|
      ex 2: “$A|”$B|“$C|”$D|“$E|”$F|“$G|”$H|“$I|”$J"$K|"$L|

      neither work.
      thanks in advance. any assistance is appreciated.

      thanks!

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @DevSrc8
        last edited by PeterJones

        @devsrc8 ,

        For | to work as logical-OR, you have to be in Regular Expression mode. But in regex mode, $ means “end of line”, not a literal dollar sign.

        Regex have prebuilt character classes which will help with your search; in your case, \u will search for an upper-case letter. So "\u will match every time there’s a quote followed by an upper case.

        5001f5e9-a811-409c-abbf-19882466a352-image.png

        To search for a literal dollar sign, you need to escape with \ it so it will be treated as a literal character: \$. So \$\u will match any uppercase letter that comes after a literal dollar sign.

        88d9954a-4336-421a-924a-81ee350d420e-image.png

        ----
        Please note that your examples sometimes had " and sometimes had “ – those are two different characters. If you had followed the advice given in “Please Read Before Posting” (which you should have seen immediately below the New Topic button that you clicked):
        8e47a553-d139-4388-8d6b-5920fa3f05bb-image.png
        and the advice it links to in the “Template for Search/Replace Questions” and “Forum Formatting Posts” FAQ entries, you would have been instructed how to present your question in a way that left no ambiguity as to which was the “right” quote characters for your data.

        DevSrc8D 1 Reply Last reply Reply Quote 1
        • DevSrc8D
          DevSrc8 @PeterJones
          last edited by

          @peterjones thanks for the quick reply!

          as well as guiding me towards very helpful artifacts that I should have reviewed.

          how do you make $\u and "\u only pull UPPER case instances?

          I will read in more depth, but simply searching for \u in an effort to locate how to only pull UPPER case letters I don’t yielded the correct information.

          section:
          Then use the following regex S/R :
          Search for: (?-i)[\u\d]\K\x20(?=[\u\d])

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @DevSrc8
            last edited by PeterJones

            @devsrc8

            how do you make $\u and "\u only pull UPPER case instances?

            \u only matches uppercase, unless you have case-insensitive match turned on. (If case insensitive is on, obviously uppercase and lowercase will both match, by definition of case insensitive)

            I don’t yielded the correct information.

            Well, you haven’t given any example data that doesn’t match your expression. That makes it harder to help you. That’s why I pointed you to those posts, because they explain the importance of providing sample data that actually matches the data that you have.

            (?-i)[\u\d]\K\x20(?=[\u\d])

            That’s a very different expression than I gave you, or than what was necessary to match text in your screenshot. That is saying “turn off case-insensitive-match; there must be an uppercase or digit, then reset the match, then find a space that is followed by uppercase or digit”. That has nothing to do with the example data you showed above.

            But given the description I just made, the expression you listed matched everything I expected in my example text below:
            69b9c722-e2b1-44c0-915f-18c469af0872-image.png

            range("A1")
            range("$I$15:$I$19")
            
            lowercase lowercase
            UPPER UPPER
            314 159
            UPPER lowercase
            lower UPPER
            314 lower
            314 UPPER
            lower 159
            UPPER 159
            

            It matches the spaces that come between two UPPER, or the spaces between two DIGITS, or the spaces between a digit and an upper in either order. That’s exactly what I would expect.

            DevSrc8D 1 Reply Last reply Reply Quote 0
            • DevSrc8D
              DevSrc8 @PeterJones
              last edited by

              @peterjones

              My apologies for not providing example data.

              with match case on:
              ad184f64-077c-4e17-9495-0a50a3f78817-image.png

              with match case off:
              5df6fe09-25f5-49b0-8f31-f66b894b96a9-image.png

              PeterJonesP 1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @DevSrc8
                last edited by

                @devsrc8 ,

                So your screenshots show exactly what I would expect. With match case on, \u only matches uppercase. With match case off, \u matches either uppercase, or, because it is ignoring case, lowercase as well. That’s how things are defined to work.

                If you want to have case-sensitive \u no matter what, use (?-i:\u) to make the parenthesized subgroup case sensitive no matter what the checkbox says:
                99d24750-eeaf-4cfe-90a8-6c2224e6d8c5-image.png

                DevSrc8D 1 Reply Last reply Reply Quote 0
                • DevSrc8D
                  DevSrc8 @PeterJones
                  last edited by DevSrc8

                  @peterjones thanks for all your help!

                  is there a marked as Solved for this forum?

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors