I would like to create a regex with the following requirements.
- First (single) char unicode letter with including and excluding option (GROUP1)
- Second (and more) char optional list with including and excluding option (GROUP2)
- End (single) char unicode letter with including and excluding option (GROUP3)
It should not be permissible for one and the same not letter to appear twice in a row, what i ve is this now
^(?!.{32})(?:[\p{L}.]*?)(?:[ ,'-][\p{L}.] )*?$
https://regex101.com/r/KmMkIk/1
CodePudding user response:
I'm unsure what you mean with your three different groupings, but by your sample data it looks like you could try:
^(?!.{136})\p{L} \.?(?:[ ,'-]?\p{L} \.?)*$
See an online demo
^- Start-line anchor;(?!.{136})- Negative lookahead to avoid a line to have 136 (or more) characters other than newline;\p{L} \.?- Any 1 (Greedy) letter from any language and an optional literal dot;(?:[ ,'-]?\p{L} \.?)*- A non-capture group (0 times) to optionally match any character from the give class and any 1 letter from any language followed by another optional dot;$- End-line anchor.
