正则表达式举例
时间:2010-02-28 来源:hs272307562
{^[yY]}
Begins with y or Y, as in a Yes answer.
{^(yes|YES|Yes)$}
Exactly "yes", "Yes", or "YES".
{^[^ \t:\]+:}
Begins with colon-delimited field that has no spaces or tabs.
{^\S+?:}
Same as above, using \S for "not space".
"^\[ \t]*$"
A string of all spaces or tabs.
{(?n)^\s*$}
A blank line using newline sensitive mode.
"(\n|^)\[^\n\]*(\n|$)"
A blank line, the hard way.
{^[A-Za-z]+$}
Only letters.
{^[[:alpha:]]+$}
Only letters, the Unicode way.
{[A-Za-z0-9_]+}
Letters, digits, and the underscore.
{\w+}
Letters, digits, and the underscore using \w.
{[][${}\\]}
The set of Tcl special characters: ] [ $ { } \
"\[^\n\]*\n"
Everything up to a newline.
{.*?\n}
Everything up to a newline using nongreedy *?
{\.}
A period.
{[][$^?+*()|\\]}
The set of regular expression special characters:
] [ $ ^ ? + * ( ) | \
<H1>(.*?)</H1>
An H1 HTML tag. The subpattern matches the string between the tags.
<!--.*?-->
HTML comments.
{[0-9a-hA-H][0-9a-hA-H]}
2 hex digits.
{[[:xdigit:]]{2}}
2 hex digits, using advanced regular expressions.
{\d{1,3}}
1 to 3 digits, using advanced regular expressions.
Begins with y or Y, as in a Yes answer.
{^(yes|YES|Yes)$}
Exactly "yes", "Yes", or "YES".
{^[^ \t:\]+:}
Begins with colon-delimited field that has no spaces or tabs.
{^\S+?:}
Same as above, using \S for "not space".
"^\[ \t]*$"
A string of all spaces or tabs.
{(?n)^\s*$}
A blank line using newline sensitive mode.
"(\n|^)\[^\n\]*(\n|$)"
A blank line, the hard way.
{^[A-Za-z]+$}
Only letters.
{^[[:alpha:]]+$}
Only letters, the Unicode way.
{[A-Za-z0-9_]+}
Letters, digits, and the underscore.
{\w+}
Letters, digits, and the underscore using \w.
{[][${}\\]}
The set of Tcl special characters: ] [ $ { } \
"\[^\n\]*\n"
Everything up to a newline.
{.*?\n}
Everything up to a newline using nongreedy *?
{\.}
A period.
{[][$^?+*()|\\]}
The set of regular expression special characters:
] [ $ ^ ? + * ( ) | \
<H1>(.*?)</H1>
An H1 HTML tag. The subpattern matches the string between the tags.
<!--.*?-->
HTML comments.
{[0-9a-hA-H][0-9a-hA-H]}
2 hex digits.
{[[:xdigit:]]{2}}
2 hex digits, using advanced regular expressions.
{\d{1,3}}
1 to 3 digits, using advanced regular expressions.
相关阅读 更多 +