• Login
Community
  • Login

Deleting all numbers with specific letter(s)

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 4 Posters 1.8k 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
    Berniukas Neziniukas
    last edited by Sep 4, 2018, 4:14 PM

    Hello. I have lines like these:
    9.15 Premjera. Senis.395 s.
    10.20 Premjera. Štutgarto kriminalinė policija.8/12 s.
    I want to delete every “395 s.” and “8/12 s.” without disturbing other numbers. Also these numbers keeps changing like (395 s., 396 s., 397 s. and 8/12 s., 8/13 s.
    Is it possible?

    S 1 Reply Last reply Sep 4, 2018, 7:35 PM Reply Quote 0
    • S
      Scott Sumner @Berniukas Neziniukas
      last edited by Scott Sumner Sep 4, 2018, 7:36 PM Sep 4, 2018, 7:35 PM

      @Berniukas-Neziniukas

      Why does it seem like every problem is a regex problem today?

      Try this:

      Find what zone: \.(?:(?:[0-9/]+)|(?:\d+))\x20s\.
      Replace with zone: leave this empty
      Wrap around checkbox: as desired
      Search mode: Regular expression
      Action: Press Replace / Replace All button

      Here’s an explanation of how it works:

      • [Match the character “.” literally][1 ] \.
      • [Match the regular expression below][2 ] (?:(?:[0-9/]+)|(?:\d+))
        • [Match this alternative (attempting the next alternative only if this one fails)][3 ] (?:[0-9/]+)
          • [Match the regular expression below][2 ] (?:[0-9/]+)
            • [Match a single character present in the list below][4 ] [0-9/]+
              • [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][5 ] +
              • [A character in the range between “0” and “9”][4 ] 0-9
              • [The literal character “/”][6 ] /
        • [Or match this alternative (the entire group fails if this one fails to match)][3 ] (?:\d+)
          • [Match the regular expression below][2 ] (?:\d+)
            • [Match a single character that is a “digit” (any symbol with a decimal value in the active code page)][7 ] \d+
              • [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][5 ] +
      • [Match the character “ ” which occupies position 0x20 (32 decimal) in the character set][8 ] \x20
      • [Match the character “s” literally (case sensitive)][6 ] s
      • [Match the character “.” literally][1 ] \.

      Created with RegexBuddy

      [1 ]: http://www.regular-expressions.info/characters.html#special
      [2 ]: http://www.regular-expressions.info/brackets.html
      [3 ]: http://www.regular-expressions.info/alternation.html
      [4 ]: http://www.regular-expressions.info/charclass.html
      [5 ]: http://www.regular-expressions.info/repeat.html
      [6 ]: http://www.regular-expressions.info/characters.html
      [7 ]: http://www.regular-expressions.info/shorthand.html
      [8 ]: http://www.regular-expressions.info/nonprint.html

      B 1 Reply Last reply Sep 5, 2018, 7:35 AM Reply Quote 2
      • G
        guy038
        last edited by Sep 5, 2018, 12:15 AM

        Hello, @berniukas-neziniukas, @scott-sumner and All,

        Scott, am I missing something obvious ?!

        As, from the sentence :

        I want to delete every “395 s.” and “8/12 s.” without disturbing other numbers.

        It seems, to my mind, that the correct search regex is, simply, the obvious one, below :

        \.(395|8/12)\x20s\.

        Cheers,

        guy038

        1 Reply Last reply Reply Quote 1
        • T
          Terry R
          last edited by Sep 5, 2018, 12:21 AM

          @guy038 it appears you did miss the obvious. That being the next sentence:

          @Berniukas-Neziniukas said:

          Also these numbers keeps changing like (395 s., 396 s., 397 s. and 8/12 s., 8/13 s.

          So the numbers aren’t always the same, hence your regex will miss other “similar” but different numbers.

          Terry

          1 Reply Last reply Reply Quote 4
          • G
            guy038
            last edited by guy038 Sep 5, 2018, 12:35 AM Sep 5, 2018, 12:35 AM

            Hi, @terry-r,

            Ah, I see ! Actually, the OP meant :

            I want to delete every expression “395 s.” and “8/12 s.” and similar ones, without disturbing other numbers, in other forms !

            I didn’t notice the difference :-((

            Best Regards,

            guy038

            B 1 Reply Last reply Sep 5, 2018, 7:56 AM Reply Quote 3
            • T
              Terry R
              last edited by Sep 5, 2018, 12:39 AM

              @guy038, yes we seem to often find posters whose primary language is NOT English, doing a fine job of writing in English, but those subtle nuances are what impart a lot more information.

              I’m actually going through the old posts (a little project of mine, we will see if it works out) and invariably the writing styles of the OPer is what causes most of the issues initially. Just getting the understanding right before launching into a regex is key to a good solution.

              Just an observation

              Terry

              1 Reply Last reply Reply Quote 4
              • B
                Berniukas Neziniukas @Scott Sumner
                last edited by Sep 5, 2018, 7:35 AM

                @Scott-Sumner This did the trick. You saved me a lot of time, thank you very much!

                1 Reply Last reply Reply Quote 1
                • B
                  Berniukas Neziniukas @guy038
                  last edited by Sep 5, 2018, 7:56 AM

                  @guy038 Sorry for being unclear! Sometimes I read my older posts and wonder how people managed to find any sense in them. That’s why I post so rarely…

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