Интерпретировать этот конкретный REGEX - PullRequest
0 голосов
/ 13 июля 2009

Некоторое время назад я сделал шаблон REGEX, и я не помню его значения. Для меня это язык только для записи:)

Вот РЕГЕКС:

"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$"

Мне нужно знать простым языком, что это значит.

Ответы [ 4 ]

5 голосов
/ 13 июля 2009
(?!^[0-9]*$)

не соответствуют только номерам,

(?!^[a-zA-Z]*$)

не совпадают только буквы,

^([a-zA-Z0-9]{8,10})$

совпадение букв и цифр от 8 до 10 символов.

4 голосов
/ 13 июля 2009

Perl Python соответственно) сообщает части (?!...):

Негативное предположение нулевой ширины. Например, /foo(?!bar)/ соответствует любому вхождению 'foo', за которым не следует 'bar'. Однако обратите внимание, что взгляд вперед и взгляд назад - это не одно и то же. Вы не можете использовать это для просмотра назад.

Это значит,

(?!^[0-9]*$)

означает: не совпадает, если строка содержит только чисел. (^: начало строки / строки, $: конец строки / строки) Другой соответственно.

Ваше регулярное выражение соответствует любой строке, которая содержит и цифр и букв, но не только одну из них.

Приветствия

Обновление: Для вашего будущего пошива RegExp взгляните на шаблон (?#...). Это позволяет встраивать комментарии в ваши регулярные выражения. Также есть модификатор re.X, но мне это не очень нравится. Это твой выбор.

2 голосов
/ 13 июля 2009

RegexBuddy говорит следующее (!?!):

(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$

Options: ^ and $ match at line breaks

Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!^[0-9]*$)»
   Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
   Match a single character in the range between “0” and “9” «[0-9]*»
      Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
   Assert position at the end of a line (at the end of the string or before a line break character) «$»
Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!^[a-zA-Z]*$)»
   Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
   Match a single character present in the list below «[a-zA-Z]*»
      Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
      A character in the range between “a” and “z” «a-z»
      A character in the range between “A” and “Z” «A-Z»
   Assert position at the end of a line (at the end of the string or before a line break character) «$»
Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
Match the regular expression below and capture its match into backreference number 1 «([a-zA-Z0-9]{8,10})»
   Match a single character present in the list below «[a-zA-Z0-9]{8,10}»
      Between 8 and 10 times, as many times as possible, giving back as needed (greedy) «{8,10}»
      A character in the range between “a” and “z” «a-z»
      A character in the range between “A” and “Z” «A-Z»
      A character in the range between “0” and “9” «0-9»
Assert position at the end of a line (at the end of the string or before a line break character) «$»  
1 голос
/ 13 июля 2009

Используйте что-то вроде expresso для анализа.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...