当前位置: 首页 > 编程语言 > C#

C#排除字符串的正则表达式分享

时间:2023-04-10 11:10:05 C#

.href="http://www.test.com/cat/1-one_piece_episodes/"href="http://www.test.com/cat/2-movies_english_subbed/"href="http://www.test.com/cat/3-english_dubbed/"href="http://www.exclude.com"这是我的正则表达式模式..href="(.*?)[^#]"并返回此href="http://www.test.com/cat/1-one_piece_episodes/"href="http://www.test.com/cat/2-movies_english_subbed/"href="http://www.xxxx.com/cat/3-english_dubbed/"href="http://www.exclude.com"排除最后一场比赛的模式是什么..或用exclude排除比赛域内部像href="http://www.exclude.com"编辑:多个排除href="((?:(?!"|bexcludeb|bxxxxb).)*)[^#]"@ridgerunner我会将正则表达式更改为:href="((?:(?!bexcludeb)[^"])*)[^#]"它匹配所有href属性,只要它们不以#结尾且不包含单词排除。解释:href="#Matchhref="(#捕获...(?:#以下组:(?!#向前看,检查字符串的下一部分是否...b#整个单词exclude#excludeb#(barewordboundaryanchors))#lookahead结束[^"]#如果成功,匹配除引号之外的任何字符)*#尽可能重复)#捕获组1结束[^#]"#匹配非#字符和结束引号。允许使用多个“禁用词”:href="((?:(?!b(?:exclude|this|too)b)[^"])*)[^#]"你的输入看起来不像有效的字符串(除非你转义它们中的引号)但你也可以在没有正则表达式的情况下这样做:stringinput="href="http://www.test.com/cat/1-one_piece_episodes/"href="http://www.test.com/cat/2-movies_english_subbed/"href="http://www.test.com/cat/3-english_dubbed/"href="http://www.exclude.com"";列表matches=newList();foreach(varmatchininput.split(newstring[]{"href"})){if(!match.Contains("exclude.com"))matches.Add("href"+match);}这样行不行?以上是C#学习教程:C#正则表达式,不包括字符串共享的所有内容,如果对你有用,需要进一步了解C#学习教程,希望大家多多关注到—href="(?!http://[^/"]+exclude.com)(.*?)[^#]"本文整理自网络,不代表立场,如涉及侵权,敬请谅解点击右边联系管理员删除如需转载请注明出处: