06/12: Regex
Regex
Example 1 :
Regex URL_REGEX = new Regex(@"url\((\""|\')?(?<path>(.*))?(\""|\')?\)", RegexOptions.Compiled);
Meaning(from Expresso)
1.url\(
2.(\""|\')?
3.(?<path>(.*))?
4.(\""|\')?
5.\)
so if a string like
url(http://search.live.com//siteowner/s/siteowner/sd.png)
with this Regex
can get
path=http://search.live.com//siteowner/s/siteowner/sd.png)
Example 3:
Example 2 :
Regex test=new Regex(“\w+”);
string text=”I am dayang”
will get a word[] ={“I”, “am”, “dayang”}
with test regex
Example 3:
Regex sss=new Regex(“\b(?<word>\w+)\s+(\k<word>)\b”);
Meaning:
1.\b :First or last character in a word
2.(?<word>\w+) :
3.\s+ : while space
4.(\k<word>)
5.\b
string text=”The the quick brown fox fox jumped over the lazy dog dog.”
will get a result with
The The
fox fox
dog dog
0 Comments:
Post a Comment
<< Home