2012-07-11 58 views
0

仅选择以#####开头并以mysig结尾的字符串。在这两者之间是允许的,但不是html标签。 string s =“##### anything mysig anthing ##### anything othersig anything ##### anything mysig”;模式的正则表达式

一个在othersig结束不应该选择

这是我一直在寻找

字符串str =“#####任何东西在这里/ 我(sig_nature) /东西在这里#####这里的任何东西/ Notmine(sig_nature) /任何东西都在这里#####东西在这里/ 我的(sig_nature) /“;

我想要的是所有以#####开头和/ 我(sig_nature)在Regex.Matches/

的foreach(赛比赛(STR,结束的文本@“[#] {5}。*/** My(sig_nature)** /“)) Console.WriteLine(match.Value.toString());

+2

你可以发布你尝试过的正则表达式吗? – 2012-07-11 12:22:31

+0

这是一个伪装的HTML解析与正则表达式问题吗? – 2012-07-11 12:23:24

+0

“^ [#] {5}。* \ b(mysig \ b)$。这将提取整个字符串..我想只提取以mysig结尾的字符串,在那里不应该有任何html标签# ####和mysig – user1502952 2012-07-11 12:25:29

回答

0

试试这个:

Regex.IsMatch(strInput, @"^#####[^<>]+mysig$"); 

解释:

^   the beginning of the string 

#####  '#####' 

\.+  '.' (1 or more times (matching the most amount possible)) 

mysig  'mysig' 

$   before an optional \n, and the end of the string 
+0

不起作用。^ [#] {5}。*(mysig)$。我希望我的签名在最后。签名是“姓名” – user1502952 2012-07-11 12:29:27

+0

你能提一些有效和无效的输入字符串吗? – Ria 2012-07-11 16:13:31

0

试试这个(很多猜测走进这):

#####(?:(?!mysig|#####)[^<>])*mysig 

这从#####到最接近的匹配mysig它可以找到,但只有在没有#####中间没有尖括号(因此没有HTML标签)。