Your Regular Expression:
Human Speak:
xxxxxxxxxx
/* Make a regex that matches (basic) URLs */
using global and exact matching
create an optional group called protocol
match "http"
possibly match "s"
match "://"
create an optional group called subdomain
repeat
match a word, then "."
create a group called domain
match 1+ words or "_" or "-"
match "."
match a word
# port, but we don't care about it, so ignore it
optionally match ":" then 0+ digits
create an optional group called path
repeat
match "/"
match 0+ words or "_" or "-"
create an optional group
# we don't want to capture the '?', so don't name the group until afterwards
match "?"
create a group called query
repeat
match 1+ words or "_" or "-"
match "="
match 1+ words or "_" or "-"
create an optional group
# fragment, again, we don't care, so ignore everything afterwards
match "#"
match 0+ any thing
Errors:
Cheat Sheet:
Full documentation available here
Matching
match "hello world"
matches "hello world" exactly
match "hello" then optionally " world"
matches "hello" or "hello world"
match "hello" or "world"
matches "hello" or "world"
match a word
matches any word
Repetition
match 0+ "hello"
matches 0 or more "hello"s
match 3 "hello"
matches exactly "hellohellohello"
match 1 to 5 "hello"
matches between 1 to 5 "hello"s
repeat 0 or more
repeats the intended text 0 or more times (default)
optionally repeat between 3 to 5
optionally repeats the indented text 3 to 5 times
Grouping
create a group called mygroup
creates a group called "mygroup"
create an optional group
creates an unnamed optional group
Using
using global and case insensitive
uses the 'g' and 'i' flags
Misc
// comment
is a single line comment
/* comment */
is a multi line comment