I am trying to create a regex pattern (in PHP) that will allow any alternation of two subpatterns. Therefore, if the pattern A corresponds to a group of three letters, and B corresponds to a group of 2 digits, they will all be in order:
aaa aaa66bbb 66 67abc 12abc34def56ghi78jkl
I do not mind which subpattern starts or ends the sequence, only after the first match the subpatterns should alternate. I am completely shocked by this - any advice would be greatly appreciated!
Here's a general solution:
^(?:[a-z]{3}(?![a-z]{3})|[0-9]{2}(?![0-9]{2}))+$
- , , . PHP:
/^(?:([a-z]{3})(?!(?1))|([0-9]{2})(?!(?2)))+$/
, , (?1), (?2) .., , - , lookaheads.
(?1)
(?2)
"/^(?:$A(?:$B$A)*$B?|$B(?:$A$B)*$A?)\$/"
A, B A, , B... B, - A-B A, .
( $), . , $A $B - (, ), ? . $A "([a-zA-Z] {3})", $B "(\ d\d)".
, , - , , , ( , ), , .
this ( ). , , , , .
/\b(?:(([a-z])\2\2)(?:(([0-9])\4)\1)*(?:([0-9])\5)?|(([0-9])\7)(?:(([a-z])\9\9)\6)*(?:([a-z])\10\10)?)\b/
char :
/\b(?:((\D)\2\2)(?:((\d)\4)\1)*(?:(\d)\5)?|((\d)\7)(?:((\D)\9\9)\6)*(?:(\D)\10\10)?)\b/
, . 3- char, 2- .
aaa 11 bbb22 33ccc ddd44ddd 55eee55 fff66fff66 77ggg77ggg
aaa11bbb
Source: https://habr.com/ru/post/1760842/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1760837/migrating-from-cs-rcs-to-mercurial&usg=ALkJrhi5Q5oOrnyfyxiKPn5W8pUtEnyP-QIs it recommended to use ASP.NET user management system on a high traffic website - c #Qt on OS X creating 10.5 compatible application on 10.6 - qtSearch table Fast sigmoid function - javaMysqlQuery force timeout from PHP - phpCreating a REST service - restSuperfish popup menu not working in IE7 - jqueryCLLocationManager - ัััะฐะฝะฝัะน ััะตัะบะฐ ะฟะฐะผััะธ - memory-leaksEffective drawing of 2D sprites (bitmaps) - c #endless jQuery cookie - javascriptAll Articles