problem with this regex: \b.{1,6}\b
-
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 “!” -
@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. -
Nice point about matching at start/end of file.
-
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
-
@Mark-Olson
Thank you very much, it worked very well…
Also thanks to everyone who tried to help.