简体   繁体   English

一个简单的正则表达式匹配

[英]A simple regex match

I have (from long ago) problems with regex matching... (I simply can't understand and remeber this damn thing...) 我(从很久以前)就遇到了正则表达式匹配的问题...(我简直无法理解和记住这该死的东西...)

However, i'd like to find a string that is the end or a table row and the beginning of another row: 但是,我想找到一个字符串,该字符串是表行的结尾或另一行的开头:

<tr>(-line-break or spaces or both...)</tr> 

I am trying with 我正在尝试

Regex.Match(_mainTable, @"</tr>*<tr>")

but it returns Empty 但它返回空

the * is a quantifier. *是一个量词。 That means zero or more of the previous match, which in your expression is the > that appears before the * .. what you what is to match "any spaces" the is indicated by the abreviation \\s which is a shortcut for: any character in the set [ \\t\\r\\n] 这意味着零个或多个先前的匹配项,在您的表达式中是在* ..之前出现的> 。您要匹配的“任何空格”是由缩写\\s表示的,这是快捷方式:任何字符在集合[ \\t\\r\\n]

so your code should be 所以你的代码应该是

Regex.Match(_mainTable, @"</tr>\s*<tr>")

只需添加\\s*即可在换行符之间进行匹配。

Regex.Match(_mainTable, @"</tr>\s*<tr>")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM