我有一个字符串
例如 AHDFFH XXXX
其中 'AHDFFH' 可以是任意长度的字符字符串。AND 'XXXX' 将重复没有。任何长度的“X”字符,需要用表中自动递增的数据库值替换。
我需要使用正则表达式从上面的字符串中找到重复的“X”字符。
谁能帮我解决这个问题..??
尝试这个:
\b(\p{L})\1+\b
解释:
<!--
\b(\p{L})\1+\b
Options: case insensitive; ^ and $ match at line breaks
Assert position at a word boundary «\b»
Match the regular expression below and capture its match into backreference number 1 «(\p{L})»
A character with the Unicode property “letter” (any kind of letter from any language) «\p{L}»
Match the same text as most recently matched by capturing group number 1 «\1+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Assert position at a word boundary «\b»
-->
你的意思是一些字符+(或一些)空格+一些数字吗?
如果是这样,你可以使用这个正则表达式:
\w+\s+(\d+)
像这样的c#代码:
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\w+\s+(\d+)");
System.Text.RegularExpressions.Match m = regex.Match("aaaa 3333");
if(m.Success) {
MessageBox.Show(m.Groups[1].Value);
}