티스토리 뷰

haracter(s) Pattern Ex. String Ex. (Pattern matches in red) Example Description & Jsfiddle Type
Meta Characters
^ /^Cat/ Cat go fast string must start with Catjsfiddle anchor
$ /slow$/ Dogs are slow string must end with slowjsfiddle anchor
* /bo*/ boom and boat and bug matches when the precedingo occurs 0 or more timesjsfiddle quantifier
+ /bo+/ boom and boat and bug matches when the precedingo occurs 1 or more timesjsfiddle quantifier
? /bo?/ boom and boat and bug matches when the precedingo occurs 0 or one timejsfiddle quantifier
. /.a/ Cats fats rats any character followed by ana jsfiddle character class
\ /4\.0/ I have a 4.0. escape the next charaterjsfiddle escape
(...) /(bug) \1's/ bug bug's and bug bugs match bug and store it in a variable called \1 which you can use later in the express to reference back to the first capture parenthesesjsfiddle group
(?:...) /(?:bug) \1's/ bug bug's and bug bugs don't capture (bug) into a variable. So no matches because \1 has no valuejsfiddle Groups
(?=...) /bug(?='s)/ bug bug's and bug bugs matches bugonly if bug is followed by 's. called a lookaheadjsfiddle lookaround
(?!...) /bug(?!'s)/ bug bug's and bug bugs matches bugonly if bug is not followed by 's called a negated lookaheadjsfiddle lookaround
...|... /foo|bar/ foo and bar is foobar matches eitherfoo or barjsfiddle alternation
{...} /fo{2}/ foo and fooo and foooooo and fo matches the previous character exactly 2 timesjsfiddle quantifier
{...,} /fo{2,}/ foo and fooo and foooooo and fo matches the previous character at least 2 timesjsfiddle quantifier
{...,...} /fo{2,4}/ foo and fooo and foooooo and fo matches the previous character at least 2 times, but no more than 4 timesjsfiddle quantifier
[...] /[cde]|[456]/ abcdefghijklmnopqrstuvwxyz 0123456789 matches any c,d, e character or 4, 5, 6characterjsfiddle character set
[...-...] /[c-u]|[4-9]/ abcdefghijklmnopqrstuvwxyz 0123456789 matches any character in the range c tou or 4 to 9jsfiddle character set
[^...] /[^c-u]/ abcdefghijklmnopqrstuvwxyz 0123456789 matches any single character not in the range ofc to u jsfiddle character set

Character Shorthands

\b /\bton\b/ tone wantons ton toon match ton if its a word character (ie. [A-Za-z0-9_]) between and start and end boundaryjsfiddle anchors
\B /ton\B/ tone wantons ton toon match ton if its NOT a word word character (ie. [A-Za-z0-9_]) between and start and end boundaryjsfiddle anchors
\d /\d/ Match digits 0123456789 matches a digit character. Equivalent to [0-9]jsfiddle character class
\D /\D/ Match non-digits 0123456789 matches any non-digit character. Equivalent to [^0-9]jsfiddle character class
\s /\s/ spaces inbetween these words and line breaks matches a single white space character, including space, tab, form feed, line feed jsfiddle character class
\S /\S/ anything 
but white space
matches a single character other than white space, including space, tab, form feed, line feed jsfiddle character class
\w /w/ abc or 123 even _ but not much else matches any alphanumeric character including the underscore. Equivalent to [A-Za-z0-9_] jsfiddle character class
\W /\W/ abc or 123 even _ but not much else matches any non-word character. Equivalent to [^A-Za-z0-9_] jsfiddle character cl

출처 : http://tech.pro/tutorial/1214/javascript-regular-expression-enlightenment

댓글
D-DAY
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/11   »
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
글 보관함