I would like to integrate an exclude from inner group email regex match, i ve tryed already to exclude character <
& >
to exclude from group [\p{L}\p{S}][^<>]
not successful.
^(?!.{256})(?:[\p{L}] (?:\.[\p{L}] )*@(?:(?:[\p{L}](?:[\p{L}\p{S}]*[\p{L}])?\.) [\p{L}](?:[\p{L}\p{S}]*[\p{L}])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\]))$
CodePudding user response:
Using \p{S}
can also match <
and >
If you don't want to match those, and keep using the character class [\p{L}\p{S}]
you can use a negative lookahead to rule out the matches for those characters.
As the part before @ can not match angle brackets, you can add another negative lookahad to the start of the string asserting not <
or >
to the right.
^(?!\S*[<>])(?!.{256})(?:[\p{L}] (?:\.[\p{L}] )*@(?:(?:[\p{L}](?:[\p{L}\p{S}]*[\p{L}])?\.) [\p{L}](?:[\p{L}\p{S}]*[\p{L}])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\]))$
See a regex demo.
CodePudding user response:
An in-line approach is to exclude <>
from the symbol class.
In order to do that replace [\p{L}\p{S}]
in 2 places with (?:\p{L}|[^\P{S}<>])
Where the \p{L}
has to be explicitly or'd.
However inside classes each item is or'd anyway, and not too efficiently.
^(?!.{256})(?:[\p{L}] (?:\.[\p{L}] )*@(?:(?:[\p{L}](?:(?:\p{L}|[^\P{S}<>])*[\p{L}])?\.) [\p{L}](?:(?:\p{L}|[^\P{S}<>])*[\p{L}])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\]))$
https://regex101.com/r/6OPVA8/1
CodePudding user response:
Use a negated intersection:
[\p{L}\p{S}&&[^<>]]
Which subtracts <>
characters, specified in an inner character class, from the outer character class of \p{L}\p{S}
.