0

I'm trying to find a straight forward way to use regex to match any string n number of characters or longer while also allowing the ability to exclude a pattern from that count.

For example, if I have:

somename
somename-with-more-text
somename-with-even-more-text
somename2
somename-with-standard-naming
somename-ttt-ttt01-naming
somename-ggg-abc09-naming

I can use the regex .{24,} to return only strings with 24 or more characters, which returns:

somename-with-even-more-text
somename-with-standard-naming
somename-ttt-ttt01-naming
somename-ggg-abc09-naming

But now I'd like to also go a step further and exclude a pattern; a literal string or regex. For example, I'd like to exclude ttt-ttt01 or maybe [a-z]{3}\d{2}. So I would be left with:

somename-with-even-more-text
somename-with-standard-naming
somename-ggg-abc09-naming

or

somename-with-even-more-text
somename-with-standard-naming

I've gotten nowhere fast trying a variety of solutions...some examples of failed attempts:

.{24,}(?<!b[a-z]{3}\d{2})
^(?!ttt01)(.{24,})
^\b(.{24,})\b(?<!ttt01)
.{24,}(?!ttt01\b)\b\w+
TryTryAgain
  • 7,632
  • 11
  • 46
  • 82
  • 2
    `^(?!.*ttt01).{24,}` – Wiktor Stribiżew Apr 09 '20 at 13:58
  • 1
    Use: `^(?!.*[a-z]{3}\d{2}).{24,}` – anubhava Apr 09 '20 at 13:59
  • 1
    You just need to add a negative lookahead like this: `(?!.*ttt-ttt01)` so it will look like this: `(?!.*ttt-ttt01).{24,}`. If the negative lookahead finds whats insinde the brackets, the whole regex wont match. I added `.*` before the `ttt-ttt01`. It means it finds everything (`.` stands for every character and the `*` say's it can be there 0 to unlimited times). So the `ttt-ttt01` can be at any certain position. A lookahead acts like a own regex, starting at the position where you add it. – Puschi Apr 09 '20 at 14:09
  • Thank you all. If anyone would like to convert comments to answer/description, I'll accept. All of those work/make sense. – TryTryAgain Apr 09 '20 at 16:38

0 Answers0