Community
    • Login

    problem with this regex: \b.{1,6}\b

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 4 Posters 292 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.
    • Bahaa0013B
      Bahaa0013
      last edited by

      I made a simple regex “\b.{1,6}\b” that matches every word contains less than 7 charecters,
      And yes it works, But the problem that it’s matching this type of words: “ab!cdefghi”, while it contains 10 charecters… maybe because it contains “!” symbol.
      so is there any way to make a regex that don’t match words contains +6 charecters even it contains a symbol like “!”

      Mark OlsonM 1 Reply Last reply Reply Quote 0
      • Mark OlsonM
        Mark Olson @Bahaa0013
        last edited by Mark Olson

        @Bahaa0013
        (?<!\S)\S{1,6}(?!\S)

        abdc!
        #$#$@
        $##@
        ~~~NO
        &
        *(
        #R%$%$%#
        abcdefg
        

        My regex will mark only first six lines, not last two.

        Note that I chose the negative assertions “not not a whitespace before or after” ((?<!\S) and (?!\S)) because that assertion matches at the beginning and end of the file, and the alternative “must be a whitespace” ((?<=\s) and (?=\s)) do not.

        Alan KilbornA Bahaa0013B 2 Replies Last reply Reply Quote 4
        • Alan KilbornA
          Alan Kilborn @Mark Olson
          last edited by

          @Mark-Olson

          Nice point about matching at start/end of file.

          1 Reply Last reply Reply Quote 1
          • guy038G
            guy038
            last edited by

            Hello, @mark-olson,

            Indeed, I would not have thought of that. As always, it is the borderline cases that need to be studied !

            Best Regards,

            guy038

            1 Reply Last reply Reply Quote 3
            • Bahaa0013B
              Bahaa0013 @Mark Olson
              last edited by

              @Mark-Olson
              Thank you very much, it worked very well…
              Also thanks to everyone who tried to help.

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