-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathIDAttribute.regex.txt
34 lines (33 loc) · 1.12 KB
/
IDAttribute.regex.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Matches an HTML ID attribute
(?<= # We only want to match an ID if it's in a tag
# but we don't want to match the tag itself, so we use a lookbehind
<[\w-]+ # to find the tag
[^>]+?(?= # and anything but closing carets
\z|id # until the end of the string or 'id'
)
)
id # now we match the id itself
\s{0,} # and optional whitespace
= # and the equal
\s{0,} # and more optional whitespace
(?> # Then, there are 3 ways we can have an ID
' # Between single quotes
(?<ID> # The ID is...
((?:
''| # any double paired quote OR
\\'| # any slash-escaped single quote
[^'] # any non-quote
)*)
)
' # followed by the closing quote
| # OR
" # double quotes
(?<ID> # The ID is...
.*? # anything until
(?<!(\\)) # a not-escape
)" # double-quote
| # OR
(?<ID> # The ID is..
[\w-]+ # any number of word characters or dashes.
)
)