正则表达式搜索“/”,“<”之类的字符和“>”

时间:2012-05-07 04:06:50

标签: regex

如果我的文字包含“\ /><”这样的字符,那么正则表达式模式应该是什么?等等,我想找到它们。这是因为正则表达式将“/”视为搜索模式的一部分,而不是单个字符。

例如,我想使用VB 2010从字符串Super Kings中找到<span>Super Kings</span>

谢谢!

2 个答案:

答案 0 :(得分:1)

试试这个:

\bYour_Keyword_to_find\b
在RegEx中使用

\b来匹配单词边界。

[编辑]

您可能正在寻找:

(?<=<span>)([^<>]+?)(?=</span>)

<强>解释

<!--
(?<=<span>)([^<>]+?)(?=</span>)

Options: case insensitive; ^ and $ match at line breaks

Assert that the regex below can be matched, with the match ending at this position (positive lookbehind) «(?<=<span>)»
   Match the characters “<span>” literally «<span>»
Match the regular expression below and capture its match into backreference number 1 «([^<>]+?)»
   Match a single character NOT present in the list “<>” «[^<>]+?»
      Between one and unlimited times, as few times as possible, expanding as needed (lazy) «+?»
Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=</span>)»
   Match the characters “</span>” literally «</span>»
-->

[/编辑]

答案 1 :(得分:1)

在正则表达式中,您必须使用/转义\

例如,尝试: <span>(.*)<\/span> <span>([^<]*)<\/span><span>(.*?)<\/span>

了解更多信息: http://www.regular-expressions.info/characters.html

相关问题