Expresions regulars
De whats Wiki
XULETARI D'EXPRESIONS REGULARS
* Patterns ("wildcards") are matched against a string
* Normal alphanumeric characters are treated as normal
* Special characters:
o . (full stop) - match any character
o * (asterix) - match zero or more of the previous symbol
o + (plus) - match one or more of the previous symbol
o ? (question) - match zero or one of the previous symbol
o \? (backslash-something) - match special characters
o ^ (caret) - match the start of a string
o $ (dollar) - match the end of a string
o [set] - match any one of the symbols inside the square braces.
o (pattern) - grouping, remember what the pattern matched as a special variable
* Examples:
o a+ matches "a", "aaaa", "aaaaaaaaaaaa", but not "bbb"
o [ab]+ matches, "a", "b", or any length combination of the two
o \.s?html? matches ".htm", ".shtm", ".html" or ".shtml"
o (.+)/1999/(.+) matches "subject/1999/psy1011/", and also stores "subject" in $1 and "psy1011/" in $2.
* Regular expressions are very extensive.
o Documentation on silas: man regex
o Friedl (1997). Mastering Regular Expressions. O'Reilly.
\{x,y\} = match x to y occurrences of the preceding. \{x\} = match exactly x occurrences of the preceding. \{x,\} = match x or more occurrences of the preceding.
Per a triar gready/nongready en una expresió regular
Per seleccionar el match més gran (per defecte):
\(.*\)
Per seleccionar el match més petit:
\(.*?\)
