Struggling with a regular expression (perl) that parses a file and returns strings from 8 to 24 characters and has no re-pattern

I am trying to find a regular expression that parses a file and returns strings of 8 to 24 characters, which have:

  • No specified character can be repeated 3 times or more (for example, "^^^guga"or && & &&& & & gt; → →> <<)))) && &>) and
  • There are no 2 consecutive repeating patterns in this line (for example, "123123"either abcabcabcdfg, or 3 ###### u3 ###### u3 ###### u)

Note. A line cannot have empty / empty space and can consist of any character that you can enter on a standard keyboard. (example 0-9a-zA-Z~!@#$%^&*()_+=-\|][{}:;"'?/.>,<`) I think I have all of them;)

Sample text

=>d`m\cc!=>d`m\cc!=>d`m`\cc!=>d`m\cc0!=>d #abcA167fegh AB&@CDAB&@CDAB&@CD 
I*dKoc,I*dKoc,I*dKoc,I*dKoc,I*dKoc, instance463instance464 Wc^^^7HjkKlp 
)FC7h#!xB;{w97SKm 12345678901234567890

Output (only 3 lines are valid)

#abcA167fegh 
instance463instance464 
)FC7h#!xB;{w97SKm
+4
source share
1 answer

This works in your example:

(?<=^|\s)(?:(?!(\S{2,})\1)(?!(\S)\2\2)\S){8,24}(?=$|\s)

Explanation:

(?<=^|\s)        # Assert we're at the start of a "word" 
(?:              # Start a non-capturing group:
 (?!(\S{2,})\1)  # Assert that no repeated sequence of characters starts here
 (?!(\S)\2\2)    # Assert that no runs of three identical characters starts here
 \S              # Match a non-whitespace character
){8,24}          # Repeat 8-24 times
(?=$|\s)         # Assert we're at the end of a "word"

See live on regex101.com .

+2
source

All Articles