regex - C# regular expression patterns -
regex - C# regular expression patterns -
i have string this:
string1=[q:6][ilvl:70](randomword) and need 3 patterns retrieve number 70 after ilvl:, number 6 after q: , and 1 other pattern retrieve ascii characters. came these 3 patterns failed because dont excactly 3 above.
string rules_1 = @"(?i)\[ilvl:([0-9]{1,2})\]"; string rules_2 = @"(?i)\[q:([0-9]{1,2})\]"; string rules_3 = @"(?i)\(([[:ascii:]+]+)\)"; the first 1 retrieves [ilvl:70] instead of 70 sec retrieves [q:6] instead of 6 , 3rd retrieves nil instead of ascii characters...
any regular look guru can help me out here?!
thank in advance.
are looking through 'group' values of match? match homecoming matched, not things in "()" , grouping '0' well.
this works expected me:
string string1="[q:6][ilvl:70](randomword)"; regex rules_1 = new regex(@"(?i)\[ilvl:([0-9]{1,2})\]"); regex rules_2 = new regex(@"(?i)\[q:([0-9]{1,2})\]"); regex rules_3 = new regex(@"(?i)\(([a-za-z]+)\)"); var match1 = rules_1.match(string1); var match2 = rules_2.match(string1); var match3 = rules_3.match(string1); var value1 = match1.groups[1].value; var value2 = match2.groups[1].value; var value3 = match3.groups[1].value; note had alter [[:ascii:]+]+ [a-za-z]+ can't nest [] selectors (it doesn't create sense one) , i've never seen :ascii:, match characters in text anyway ([,:,0,7,etc. ascii characters)
c# regex
Comments
Post a Comment