regex.matches ?
-
hi everybody, I have a text like this:
<img align=left valign=top src=http://www.takvim.com.tr/2008/09/11/im/7BC7F044C2062649A63A5239b.jpg alt='Bozacı, şıracı dolmuşçu' height=160 border=0 >
and I have pattern like this:
pattern = (?<name>\b\w+\b)\s*=\s*("(?<value>[^"]*)"|'(?<value>[^']*)'| (?<value>[^"'<> \s]*) |(?<value>[^"'<> \s]+)\s*)+
I wnat to get "src" block.
foreach (Match submatch in Regex.Matches(pattern))
{
submatch.groups.... // It returns allways 2 groups
}It returns allways 2 groups; In this case it returns: submatch.groups[1] = align submatch.groups[2] = border But I need http://www.takvim.com.tr/2008/09/11/im/7BC7F044C2062649A63A5239b.jpg By the way, I have no only that template text. it can be: <a href=gnb102.html> or <a href="gnb102.html"> or href=gnb102.html or href="gnb102.html" etc... Any Ideas? Thanx...
I want to fly but I don't have wings
-
hi everybody, I have a text like this:
<img align=left valign=top src=http://www.takvim.com.tr/2008/09/11/im/7BC7F044C2062649A63A5239b.jpg alt='Bozacı, şıracı dolmuşçu' height=160 border=0 >
and I have pattern like this:
pattern = (?<name>\b\w+\b)\s*=\s*("(?<value>[^"]*)"|'(?<value>[^']*)'| (?<value>[^"'<> \s]*) |(?<value>[^"'<> \s]+)\s*)+
I wnat to get "src" block.
foreach (Match submatch in Regex.Matches(pattern))
{
submatch.groups.... // It returns allways 2 groups
}It returns allways 2 groups; In this case it returns: submatch.groups[1] = align submatch.groups[2] = border But I need http://www.takvim.com.tr/2008/09/11/im/7BC7F044C2062649A63A5239b.jpg By the way, I have no only that template text. it can be: <a href=gnb102.html> or <a href="gnb102.html"> or href=gnb102.html or href="gnb102.html" etc... Any Ideas? Thanx...
I want to fly but I don't have wings
-
Set the ExplicitCapture flag when creating the Regex.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)it has "RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture" interesting point is: if the text has " or ' it's working correctly ex 1: <img src="http://www.takvim.com.tr/i/spacer\_trans\_1x1.gif" width="10" height="1"> ex 2: <img src=http://www.takvim.com.tr/i/spacer\_trans\_1x1.gif width=10 height=1> ex 1: is working ex 2: doesn't work
I want to fly but I don't have wings
-
hi everybody, I have a text like this:
<img align=left valign=top src=http://www.takvim.com.tr/2008/09/11/im/7BC7F044C2062649A63A5239b.jpg alt='Bozacı, şıracı dolmuşçu' height=160 border=0 >
and I have pattern like this:
pattern = (?<name>\b\w+\b)\s*=\s*("(?<value>[^"]*)"|'(?<value>[^']*)'| (?<value>[^"'<> \s]*) |(?<value>[^"'<> \s]+)\s*)+
I wnat to get "src" block.
foreach (Match submatch in Regex.Matches(pattern))
{
submatch.groups.... // It returns allways 2 groups
}It returns allways 2 groups; In this case it returns: submatch.groups[1] = align submatch.groups[2] = border But I need http://www.takvim.com.tr/2008/09/11/im/7BC7F044C2062649A63A5239b.jpg By the way, I have no only that template text. it can be: <a href=gnb102.html> or <a href="gnb102.html"> or href=gnb102.html or href="gnb102.html" etc... Any Ideas? Thanx...
I want to fly but I don't have wings
I think you grouping might be incorrect. Try do the isolated cases first, then combine them once they are working. Currently you have no idea if it is the regex that is incorrect or the way the grouping has been constructed (it may be that it only allows the define the grouping name once, in that case you need to wrap the grouping around all possible options).
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
I think you grouping might be incorrect. Try do the isolated cases first, then combine them once they are working. Currently you have no idea if it is the regex that is incorrect or the way the grouping has been constructed (it may be that it only allows the define the grouping name once, in that case you need to wrap the grouping around all possible options).
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008):sigh: I tried with "The Regex Coach" program. There is no problem with pattern, it's working for all cases. It seperates to groups correctly. :confused: I'm confused...
(?<name>\b\w+\b)\s*=\s*("(?<value>[^"]*)"|'(?<value>[^']*)'| (?<value>[^"'<> \s]*) |(?<value>[^"'<> \s]+)\s*)+
may be ?<name> and ?<value> are problem. I don't know...
I want to fly but I don't have wings
-
:sigh: I tried with "The Regex Coach" program. There is no problem with pattern, it's working for all cases. It seperates to groups correctly. :confused: I'm confused...
(?<name>\b\w+\b)\s*=\s*("(?<value>[^"]*)"|'(?<value>[^']*)'| (?<value>[^"'<> \s]*) |(?<value>[^"'<> \s]+)\s*)+
may be ?<name> and ?<value> are problem. I don't know...
I want to fly but I don't have wings
enginço wrote:
I tried with "The Regex Coach" program. There is no problem with pattern, it's working for all cases.
Then you probably did something wrong when copying the regex expression to code.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
enginço wrote:
I tried with "The Regex Coach" program. There is no problem with pattern, it's working for all cases.
Then you probably did something wrong when copying the regex expression to code.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)thanx for your reply, I found the problem | (?[^"'<> \s]*) | is wrong |(?\w[^"'<> \s]*)| is correct But both is OK on The Regex Coach program, in C# it's behave different. Infact I don't know how is working getting groupCollection. :) Anyway, it's solved. Thanx
I want to fly but I don't have wings
modified on Thursday, September 11, 2008 7:48 AM