Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 4 Posters 589 Views 1 Watching
    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 Offline
      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 Offline
        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 Offline
          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 Online
            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 Offline
              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

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors