1 <span class='Txt9Gray'>Decisions ( </span>
I'm trying to grab the 1
from this string. Before the 1
is another span
, but I can't use that as a marker because it can change from page to page. Is there any regex expression that can simply grab the 1
?
我正试图从这个字符串中抓取1。在1之前是另一个跨度,但我不能将其用作标记,因为它可以在页面之间进行更改。是否有任何正则表达式可以简单地抓住1?
The word Decisions
will always exist. That's my main way to find this line. Here's what I have been trying to no avail:
决策一词将永远存在。这是我找到这条线的主要方式。这是我一直试图无济于事的:
strRegex.Append("(?<strDecisionWins>[^<]+)[\s]*?
<span class='[\s\w\W]*'>\bDecisions\b \([\s\w\W]*?</span>")
This keeps grabbing the spans
before the actual 1
. The full line containing the above is:
这样可以在实际的1之前抓住跨度。包含上述内容的整行是:
<span class='Txt9Gray'>(T)KOs ( </span> 66.67 <span class='Txt9Gray'>%) </span> <br /> 1 <span class='Txt9Gray'>Decisions ( </span> 33.33 <span class='Txt9Gray'>%) </span> <br />
The problem is that the match is matching the very beginning, instead of the one piece.
问题是匹配从一开始就匹配,而不是一个匹配。
1 个解决方案
#1
How about:
\d+(?=\s*\<[^\>]+\>[^\<]*\bDecisions\b)
\d+(?=\s*<[^>]+>[^<]*\bDecisions\b)
That would only select 1 (and nothing else)
那只会选择1(没有别的)
The second form is for regex processor which does not need to escape <
and >
.
第二种形式用于正则表达式处理器,它不需要转义 <和> 。
The lookahead expression (?=...)
guarantees to select a number \d+
followed by an element () containing a text (meaning no opening '<
': [^<]*
), which includes the word Decisions.
前瞻表达式(?= ...)保证选择一个数字\ d +后跟一个包含文本的元素()(意思是没有开头'<':[^ <] *),其中包括单词Decisions。
The lookahead technique can be combined with other regex like:
先行技术可以与其他正则表达式结合使用:
\s\d(?=\s*\<[^\>]+class\s*=\s*'Txt9Gray'[^\>]*\>)
\s\d(?=\s*\<[^>]+class\s*=\s*'Txt9Gray'[^>]*>)
would grab a single digit (provided it follows a space), followed by an element containing the attribute 'class='Txt9Gra
y''
会抓住一个数字(假设它跟随一个空格),然后是一个包含属性'class ='Txt9Gray''的元素
#1
How about:
\d+(?=\s*\<[^\>]+\>[^\<]*\bDecisions\b)
\d+(?=\s*<[^>]+>[^<]*\bDecisions\b)
That would only select 1 (and nothing else)
那只会选择1(没有别的)
The second form is for regex processor which does not need to escape <
and >
.
第二种形式用于正则表达式处理器,它不需要转义 <和> 。
The lookahead expression (?=...)
guarantees to select a number \d+
followed by an element () containing a text (meaning no opening '<
': [^<]*
), which includes the word Decisions.
前瞻表达式(?= ...)保证选择一个数字\ d +后跟一个包含文本的元素()(意思是没有开头'<':[^ <] *),其中包括单词Decisions。
The lookahead technique can be combined with other regex like:
先行技术可以与其他正则表达式结合使用:
\s\d(?=\s*\<[^\>]+class\s*=\s*'Txt9Gray'[^\>]*\>)
\s\d(?=\s*\<[^>]+class\s*=\s*'Txt9Gray'[^>]*>)
would grab a single digit (provided it follows a space), followed by an element containing the attribute 'class='Txt9Gra
y''
会抓住一个数字(假设它跟随一个空格),然后是一个包含属性'class ='Txt9Gray''的元素