
本文共 13166 字,大约阅读时间需要 43 分钟。
- ���������[���]������������������������������������������������������������������������������������������
- \w���������������������������������(���������������)������������������(���������[a-zA-Z0-9_]),���������������������������
- \W: ���������������������������������������������������
- \s���������������������������(���������[\f\n\r\t\v])���
- \S������������������������������(���������[^\f\n\r\t\v])���
- https? ���������������������������������������������������http,���������������https���?���������������������:������������������(s)���������������������������������������������
- {}������������������������������������������������������������������������(������������������������������).���������,{3,}������������������3������������������������������������������������3���������������������
- ������������������: *? (������*������������������)���
- ������������������������������������������������������
������������������ | ������������������ |
* | *? |
+ | +? |
{n,} | {n,}? |
- ������������
���������cat������������cat,���������������������category,������������������������cat,������������������\bcat\b���������(b���boundary(������)���������),���������������������������������������������������\B.
- .*���������������������������(.������������������������������)
- ������JavaScript���������������������������:
(?m)^\s*//.*$ |
���������������
(?m) ������������
^���$ ������������������������������
\s* ���������������������������������
// ������������������
.* ������������������������������������
- ���������������(���),���������������������������������������������������������IP���������������������������������������������������
\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}
���������������
(\d{1,3}.){3}\d{1,3}
������������������������������������999.999.999.999������������������������������������������������IP������������������������������
- ��������������� ���������������������������(\d{1,2})
- ������������������������1��� 1\d{2}
- ������������������������2���2[0-4]\d
- ������������������������25���25[0-5]
������������������������������������������������
(((\d{1,2})|(1\d{2})|(2[0-4]\d)|( 25[0-5]))\.){3}((\d{1,2})|(1\d{2})|(2[0-4]\d)|( 25[0-5]))
- ������������
������������������������������������������������������������������������������������������������������������
���������������������
This is is a text, and I want to know know if there is any repeated words in it.
���������������������������������������
[ ]+(\w+)[ ]+\1
���������������������������������������������������������������
is is
know know
������������������������������������[ ]+������������������������������\w+������������������������������������������[ ]+���������������������������������\w+���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������\1,���������������������������������������������������������������������������������������������(\w+)���������������is������������\1���������������is������(\w+)���������������know������������\1������������know.
������\1���������������������������������������������������������������������\2���������������������������,\3������������������������������������������������������������������������������������[ ]+(\w+)[ ]+\1���������������������������������������������������
- ==============================================================================
������������������
. | ������������������������ |
| | ������������������ |
[] | ������������������������������������ |
[^] | ��������������������� |
- | ���������������������������A-Z��� |
\ | ������������������������ |
���������������
* | ���������������������(������������)������������������������ |
*? | *������������������ |
+ | ���������������������(������������)������������������������ |
+? | +������������������ |
? | ������������������������(������������)��������������������� |
{n} | ���������������������(������������)���n��������� |
{m,n} | ���������������������(������������)������m������������n��������� |
{n,} | ���������������������(������������)n��������������������� |
{n,}? | {n,}������������������ |
���������������
^ | ������������������������ |
\A | ������������������������ |
$ | ������������������������ |
\Z | ������������������������ |
\< | ��������������������� |
\> | ��������������������� |
\b | ��������������������������������������� |
\B | \b��������� |
���������������������
[\b] | ������������ |
\c | ������������������������ |
\d | ������������������������ |
\D | \d��������� |
\f | ��������� |
\n | ��������� |
\r | ��������� |
\s | ������������������������ |
\S | \s��������� |
\t | ���������(Tab������) |
\v | ��������������� |
\w | ������������������������������������������������ |
\W | \w��������� |
\x | ������������������������������ |
\o | ��������������������������� |
���������������������������
() | ������������������������ |
\1 | ���������������������������,\2���������������������������,������������ |
?= | ������������ |
?<= | ������������ |
?! | ��������������� |
?<! | ��������������� |
?() | ������(if then) |
?()| | ������(if then else) |
���������������
\E | ������\L������\U��������� |
\l | ��������������������������������� |
\L | ������������������������������������������������\E������ |
\u | ��������������������������������� |
\U | ������������������������������������������������\E������ |
������������
(?m) | ������������������ |
- ������������
���������������������������������������������������������������?=���������������������������������������������������=������������
������������������������������URL���������http������https,������������������������������
http://www.cnblogs.com
���������������:.+(?=:)
���������: http
������������.+(:) ,������ http:
- ������������
������������������������������������������������������(���������������)���������������?<=
������������ABC0: $12.56
������������ (?<=\$)[0-9.]+
������������?<=������������$12.56,���������12.56
- ������������������������
���������������������
<head>
<title>Ben Forta���s HomePage</title>
</head>
���������������������������<title>���</title>������������������������������������<title>���</title>���������������������������������������������������������������������������������������������������������������������������������������������������:
������������������(?<=<title>).*?(?=</title>)
���������������������������������������������������������������������������������������������������������������������������������������������������������������
��������� | ������ |
(?=) | ��������������� |
(?!) | ��������������� |
(?<=) | ��������������� |
(?<!) | ��������������� |
- ���������������
���������:I paid $30 for 100 apples.
������������\b(?<!\$)\d+\b
���������������������������������$������������������������������������������100
���������������������������������������������������������������
- ���������������������������������
������������������������������������������������������������������������������������������?������������������������������������������������������
- ���������������������������������������������
- ���������������������������������������������
���������������������������������������������������������������������<img>���������������������������������������������������<img>������������������������(������������<A>���</A>������������)������������������������������������������������������
������������������������������������?(backreference)true-regex, ������?���������������������������������������backreference������������������������true-regex���������������backreference���������������������������������������������
<!-- Nav Bar --> <TD> <a href='/home'><img src='/images/home.gif'></a> <img src=/images/spacer.gif'> <a href='/search'><img src='/images/search.gif'></a> <img src='/images/spacer.gif'> <a href='/help'><img src='/images/help.gif'></a> </td>
|
���������������������
(<[Aa]\s+[^>]+>\s*)?<[Ii][Mm][Gg]\s+[^>]+>(?(1)\s*</[Aa]>)
���������������
(<[Aa]\s+[^>]+>\s*)?������������������������������<A>������<a>������
<[Ii][Mm][Gg]\s+[^>]+>������������<img>���������������������������������
(?(1)\s*</[Aa]>)������������������������������������?(1)���������������������������������������(���������������������������<A>������)������������������\s*</[Aa]>������������������(���������������������������������<A>���������������������������������������������������)���������(1)������,\s*</[Aa]>���������������������</A>������������������������������������
���������.NET���������������������
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Drawing; namespace RegularExpressionConsoleApplication { class Program { static void Main(string[] args) { //LoopBackMatch(); //������������(������������������) //LoopForwardMatch(); //������������(?=) //LoopAfterwardMatch(); //������������(?<=) //LoopForwardAndAfterwardMatch(); //������������������������ ConditionItems(); //��������������������������� } ////// ������������ /// static void LoopForwardMatch() { string text = " http://www.cnblogs.com"; string expression = @".+(?=:)"; Regex reg = new Regex(expression, RegexOptions.IgnoreCase); MatchCollection mc = reg.Matches(text); foreach (Match match in mc) { Console.WriteLine(match.Value); } Console.ReadKey(); } ////// ������������ /// static void LoopAfterwardMatch() { string text = "ABC01: $12.56"; string expression = @"(?<=\$)[0-9.]+"; Regex reg = new Regex(expression, RegexOptions.IgnoreCase); MatchCollection mc = reg.Matches(text); foreach (Match match in mc) { Console.WriteLine(match.Value); } Console.ReadKey(); } ////// ������������������������ /// static void LoopForwardAndAfterwardMatch() { StringBuilder sbStr = new StringBuilder(); sbStr.Append(""); sbStr.Append("\r\n "); sbStr.Append("Ben Forta's HomePage "); sbStr.Append("\r\n"); sbStr.Append(""); string expression = @"(?<=).*?(?= )"; Regex reg = new Regex(expression, RegexOptions.IgnoreCase); MatchCollection mc = reg.Matches(sbStr.ToString()); foreach (Match match in mc) { Console.WriteLine(match.Value); } Console.ReadKey(); } ////// ��������������������������������������� /// /// static void LoopBackMatch() { string text = " this is is a text, and I want to know know if there is any repeated words in it."; string expression = @"[ ]+(\w+)[ ]+\1"; Regex reg = new Regex(expression, RegexOptions.IgnoreCase); MatchCollection mc = reg.Matches(text); foreach (Match match in mc) { Console.WriteLine(match.Value); } Console.ReadKey(); } ////// ������������,���������������������: /********************************************************* * * * static void ConditionItems() { StringBuilder text = new StringBuilder(); text.Append(" "); text.Append("\r\n"); text.Append(""); text.Append("\r\n"); text.Append("*
*
*
*
* *********************************************************/ ///
"); text.Append("\r\n"); text.Append("
"); text.Append("\r\n"); text.Append("
"); text.Append("\r\n"); text.Append("
"); text.Append("\r\n"); text.Append("
"); text.Append("\r\n"); text.Append(""); string expression = @"( ]+>\s*)?
]+>(?(1)\s*)"; Regex reg = new Regex(expression, RegexOptions.IgnoreCase); MatchCollection mc = reg.Matches(text.ToString()); //foreach (Match match in mc) //{ // Console.WriteLine(match.Value); //} Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("the total count of match result is: " + mc.Count); for (int i = 0; i < mc.Count; i++) { Match match = mc[i]; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("|-Match["+i+"] is :"+match.Value); GroupCollection groups = match.Groups; for (int j = 0; j < groups.Count; j++) { Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("|---Groups[" + j + "] is :" + groups[j]); } } Console.ReadKey(); } } }
������������������������������������������
发表评论
最新留言
关于作者
