[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Паттерн
shvedsd
Помогите разобрать паттерн по полочкам, а то не понятно как он работает
elseif(!preg_match("/^(https?:\/\/)?([\w\.]+)\.([a-z]{2,6}\.?)(\/[\w\.]*)*\/?$/", $site))
Oyeme
/^(https?:\/\/)?([\w\.]+)\.([a-z]{2,6}\.?)(\/[\w\.]*)*\/?$/

^ assert position at start of the string
1st Capturing group (https?:\/\/)?
Quantifier: ? Between zero and one time, as many times as possible, giving back as needed [greedy]
Note: A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
http matches the characters http literally (case sensitive)
s? matches the character s literally (case sensitive)
Quantifier: ? Between zero and one time, as many times as possible, giving back as needed [greedy]
: matches the character : literally
\/ matches the character / literally
\/ matches the character / literally
2nd Capturing group ([\w\.]+)
[\w\.]+ match a single character present in the list below
Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
\w match any word character [a-zA-Z0-9_]
\. matches the character . literally
\. matches the character . literally
3rd Capturing group ([a-z]{2,6}\.?)
[a-z]{2,6} match a single character present in the list below
Quantifier: {2,6} Between 2 and 6 times, as many times as possible, giving back as needed [greedy]
a-z a single character in the range between a and z (case sensitive)
\.? matches the character . literally
Quantifier: ? Between zero and one time, as many times as possible, giving back as needed [greedy]
4th Capturing group (\/[\w\.]*)*
Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
Note: A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
\/ matches the character / literally
[\w\.]* match a single character present in the list below
Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
\w match any word character [a-zA-Z0-9_]
\. matches the character . literally
\/? matches the character / literally
Quantifier: ? Between zero and one time, as many times as possible, giving back as needed [greedy]
$ assert position at end of the string
Миша
Цитата (shvedsd @ 14.08.2015 - 19:20)
Помогите разобрать паттерн по полочкам, а то не понятно как он работает
elseif(!preg_match("/^(https?:\/\/)?([\w\.]+)\.([a-z]{2,6}\.?)(\/[\w\.]*)*\/?$/", $site))

Я любитель, если что профессионалы поправят

preg_match — Выполняет проверку на соответствие регулярному выражению

/ / Границы, можно так # #

Должно начинаться с ^

Заканчивается $

Потом https?:

экранировать / можно так \ - \/\/

Символ ? говорит, что может быть или не быть конструкции (https?:\/\/)

([\w\.]+) все буквы, все цифры и знак подчеркивания, + минимум 1 символ

\. экранировать точку

([a-z]{2,6}\.?) - любые анг символы минимум 2, максимум 6, затем точка

(\/[\w\.]*)* - символ / , потом все буквы, все цифры и знак подчеркивания - любое количество

\/? / , ? - говорит, что может быть или не быть


_____________
Принимаю заказы, писать в ЛС
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.