我想匹配“<”之间的 n 个字符和“>”人物。例如,
我希望能够匹配
或
http://www.learnmore.com/>
本质上具有相同的模式。这是因为,我收到的字符串在特殊字符之间可能有 n 个字符。一旦我匹配包含特殊字符的模式,我将用空格替换它。 (我目前能够做到的——替换部分。)。我只需要匹配部分的帮助。
I want to match n number of characters between a "<" and ">" characters. For example,
I want to be able to match <a href = "image1.jpg">
or
<a href = " http://www.learnmore.com/>
essentially with the same pattern. This is because, the strings I receive might have n number of characters between the special characters. Once I match the pattern which includes the special characters, I will replace it with a blank space(which I am able to do currently---the replacing part.). I need help with the matching part only.
发布评论
评论(3)
强制 “不要尝试使用正则表达式解析 HTML”链接< /a>
Obligatory "don't try to parse HTML with regex" link
您可以尝试使用以下正则表达式
来匹配您的字符串(假设
>
不是问题中的格式错误,而是字符串中的实际内容)。You can try the following regular expression
to match against your string (assuming the
>
was not a formatting error in your question but the actual content in the string).首先将
>
替换为>
,将<
替换为<
。然后像往常一样使用正则表达式或其他方式进行模式匹配。First replace
>
with>
and<
with<
. Then do your pattern matching as usual using regex or whatever.