Regex negation for two consecutive numbers -
i'm trying create regex blew mind. how make regex negation below when have 2 consecutive numbers?
/^([\p{l}\p{n}\. ]+)(, ?| )([0-9-]+[a-z]?)(, ?| |$)(.*)/iu
valid examples:
text text 123 text text, 123, text text 123b text text, 123b, text 123 text 123b text, 123, text, 123b, 987 123 987 123b 987, 123, 987, 123b,
(need be) invalid examples:
text text 456 123 text text, 456, 123, text text 456 123b text text, 456, 123b, text 456 123 text 456 123b text, 456, 123, text, 456, 123b, 987 456 123 987 456 123b 987, 456, 123, 987, 456, 123b,
but guys can see, examples above valid regex: https://regex101.com/r/6t5oq5/4
requirements: first group may have letters or numbers. second group can have numbers or numbers followed letter, , third group can have anything. groups can separated commas or space. , letters , numbers can size. there can not consecutive numbers in string, unless number in first group or in last group (anything).
what best way this?
based on posted, use pattern ^(\s+)(?=[^\d\r\n]+\d+[^\d\r\n]+$).*
demo
^ # start of string/line ( # capturing group (1) \s # <not whitespace character> + # (one or more)(greedy) ) # end of capturing group (1) (?= # look-ahead [^\d\r\n] # character not in [\d\r\n] character class + # (one or more)(greedy) \d # <digit 0-9> + # (one or more)(greedy) [^\d\r\n] # character not in [\d\r\n] character class + # (one or more)(greedy) $ # end of string/line ) # end of look-ahead . # character except line break * # (zero or more)(greedy)
Comments
Post a Comment