![](/img/trans.png)
[英]Why doesn't this regex pattern match this text? (Simple regex just includes escaped text with wildcard in the middle)
[英]Simple Regex Doesn't match
我有一個簡單的C ++,COM可見的regex實用程序,它根據是否找到匹配項返回true / false。 像A
[A]
(從單元測試中的方法簽名借用)這樣A
表達式匹配。 一個很好的表達式來匹配Excel范圍字符串(A1:Z10)
很好用。 但是這樣的表達
This is a long sentence.
[A-Za-Z]*
帶有或不帶有忽略大小寫的字符,將不匹配。 我已經嘗試過可以想到的變體形式: \\w[AZ]*
(忽略大寫字母設置)、. NET多種\\ p ...(有些東西,現在不記得了!)。 什么都沒有。 有趣的是,我在VS2012中有兩個不同的regex測試器插件,它們都說regex在句子上確實匹配。
/ EDIT /認為這不會有多大幫助,但這是C ++代碼的有效部分:
<!-- language: lang-cpp -->
varRegex.ChangeType(VT_BSTR);
using namespace std::regex_constants;
wregex regexPredicate((wchar_t*)varRegex.bstrVal, ECMAScript|icase);
if (varValue.vt == VT_BSTR)
{
pRetVal->vt = VT_BOOL;
pRetVal->boolVal = std::regex_match( static_cast<wchar_t*>(varValue.bstrVal), regexPredicate )
? VARIANT_TRUE : VARIANT_FALSE;
}
嗯...我一定使用不正確。
思考?
謝謝。
對於您的示例字符串, This is a long sentence.
您需要使用量詞。
[a-zA-Z\. ]* matches any character of a-z or A-Z, ' ' and '.' (0 or more times)
可以識別以下量詞。
* Match 0 or more times
+ Match 1 or more times
? Match 1 or 0 times
{n} Match exactly n times
{n,} Match at least n times
{n,m} Match at least n but not more than m times
“這句話很長。” “[A-ZA-Z]”
您可能是說“ [A-Za-z]” //最后一個“ z”很小
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.