• Login
Community
  • Login

how to check if 160th character of every line is 'Z' ?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 3 Posters 1.9k 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.
  • B
    Bhalchandra Metkari
    last edited by Bhalchandra Metkari Dec 21, 2021, 5:18 PM Dec 21, 2021, 5:16 PM

    how to check if 160th character of every line is ‘Z’ ?

    A 1 Reply Last reply Dec 21, 2021, 5:23 PM Reply Quote 0
    • A
      Alan Kilborn @Bhalchandra Metkari
      last edited by Dec 21, 2021, 5:23 PM

      @bhalchandra-metkari

      So that implies that you want to find lines where the 160th character is NOT a Z?

      You could do that with:

      find: ^(?-is).{159}(?!Z)
      mode: regular expression

      B 1 Reply Last reply Dec 21, 2021, 5:25 PM Reply Quote 2
      • B
        Bhalchandra Metkari @Alan Kilborn
        last edited by Dec 21, 2021, 5:25 PM

        @alan-kilborn Actually I want to find lines where the 160th character is a ‘Z’ character

        A 1 Reply Last reply Dec 21, 2021, 5:28 PM Reply Quote 0
        • A
          Alan Kilborn @Bhalchandra Metkari
          last edited by Dec 21, 2021, 5:28 PM

          @bhalchandra-metkari

          find: ^(?-is).{159}(?=Z)

          B 2 Replies Last reply Dec 21, 2021, 5:31 PM Reply Quote 3
          • B
            Bhalchandra Metkari @Alan Kilborn
            last edited by Dec 21, 2021, 5:31 PM

            @alan-kilborn You are a genius ! it worked …Thank you so much

            1 Reply Last reply Reply Quote 1
            • B
              Bhalchandra Metkari @Alan Kilborn
              last edited by Dec 21, 2021, 6:05 PM

              @alan-kilborn is there any way to 1) find lines where the 160th character is a ‘Z’ character and 130th character/digit is 0 2) find lines where the 160th character is a ‘Z’ character or 130th character/digit is 0

              P 1 Reply Last reply Dec 21, 2021, 6:55 PM Reply Quote 0
              • P
                PeterJones @Bhalchandra Metkari
                last edited by PeterJones Dec 21, 2021, 6:55 PM Dec 21, 2021, 6:55 PM

                @bhalchandra-metkari ,

                See the FAQ which notes:

                Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first few (one to three) data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.

                But as your second freebie:

                You asked

                160th character is a ‘Z’ character and 130th character/digit is 0

                As with any regex, this can be done in multiple ways.

                One way would be to do 129 of any character (where the . that Alan showed means “match any character ”, and the {###} that Alan showed is the multiplying operator to show how many copies of the previous token should be matched), then a 0, then 29 of any, then a Z: ^(?-is).{129}0.{29}

                But since you’re also asking for an OR version, another way to do AND is with two separate lookaheads: ^(?-is)(?=.{129}0)(?=.{159}Z).*$ which says, match case-sensitive with . not matching newline, such that the line is required to have 129 characters from the beginning followed by a 0, and the line is required to have 159 characters from the beginning followed by a Z; then use .*$ to match the whole line (because if your entire match is in (?=…) lookaheads, it will be a confusing zero-width match.

                160th character is a ‘Z’ character or 130th character/digit is 0

                The OR version is to wrap the two lookaheads with an OR control inside a group :
                ^(?-is)(?:(?=.{129}0)|(?=.{159}Z)).*$ – which says, from beginning of line, case sensitive, . not match newline, matching either 129-then-0 or 159-then-Z or both, then grab the whole line.

                A 1 Reply Last reply Dec 21, 2021, 6:58 PM Reply Quote 2
                • A
                  Alan Kilborn @PeterJones
                  last edited by Alan Kilborn Dec 21, 2021, 6:58 PM Dec 21, 2021, 6:58 PM

                  Additional helpful information for combining search criteria is found HERE.

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