I am writing this regex to detect patterns like mypage?myvar1=myvalue2&myvar2&myvar3=myvalue3
: basically a simple file without extension + parameters regex.
So here is my code:
preg_match("#([a-zA-Z0-9]+)((\?)((([a-zA-Z0-9]+)((=)([a-zA-Z0-9]+))?)((&)([a-zA-Z0-9]+)((=)([a-zA-Z0-9]+))?)*))?#",$foo);
It's ugly and hard to understand right ?
So what I want to do is something like this :
preg_match
(
"#
([a-zA-Z0-9]+)
(
(\?)
(
(
([a-zA-Z0-9]+)
(
(=)
([a-zA-Z0-9]+)
)?
)
(
(&)
([a-zA-Z0-9]+)
(
(=)
([a-zA-Z0-9]+)
)?
)*
)
)?
#"
,
$foo
);
and i also want to add comments at the end of each lines to further explain my code to future me when i review it again.
Of course if I do it like this I will have spaces and new lines that will mess my regex and it won't work.I also want to add comments at the end of some of the lines to further explain my code to future me when i review it again.
How do I do that ?