在Yahoo-Pipes中,当你看不到不可打印的字符和html标签时如何使用正则表达式?

发布于 2024-08-21 20:49:00 字数 110 浏览 9 评论 0原文

我在尝试使用正则表达式提取数据时遇到问题,而我的结果不是我想要的,因为字符串中可能有一些换行符、空格、html 标签等,但无论如何可以实际查看字符串中的内容,调试器似乎只显示真实的文本。你如何处理这个问题?

I keeping having the problem trying to extract data using regex whereas my result is not what I wanted because there might be some newlines, spaces, html tags, etc in the string, but is there anyway to actually see what is in the string, the debugger seems to show only the real text. How do you deal with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海的爱人是光 2024-08-28 20:49:00

如果字符串的内容是 HTML,那么调试器会让您选择查看“HTML”或“Source”。源代码应该向您显示其中的所有 HTML 标记。

但是,如果您担心的是空白,这可能还不够。您唯一的选择是在原始页面上“查看源代码”。

最好的做法是在正则表达式中明确处理这些可能性。例如,如果您认为目标字符串中可能出现空格,请在关键位置使用 \s* 模式。这将匹配零个或多个空格、制表符和新行(您还必须在新行的正则表达式面板中选中“s”选项)。

但是,如果没有源文本和您正在使用的正则表达式的具体示例,建议只能是通用的。

If the content of the string is HTML then debugger gives you a choice of viewing "HTML" or "Source". Source should show you any HTML tags that are there.

However if your concern is white space, this may not be enough. Your only option is to "view source" on the original page.

The best course of action is to explicitly handle these possibilities in your regex. For example, if you think you might be getting white space in your target string, use the \s* pattern in the critical positions. That will match zero or more spaces, tabs, and new lines (you must also have the "s" option checked in the regex panel for new lines).

However, without specific examples of source text and the regex you are using - advice can only be generic.

糖粟与秋泊 2024-08-28 20:49:00

我所做的是使用正则表达式测试器(无论哪个使用与您正在使用的相同正则表达式引擎),并在其上测试我的模式。我尝试过使用显示不可见字符的文本编辑器,但对我来说它们只会增加混乱。

所以我只是不断尝试和犯错。例如,如果一行以: 结尾,

</a>

那么我将在正则表达式测试器上尝试以下模式,直到找到一个有效的模式:

</a>.
</a>..
</a>\s
</a>\s*
</a>\n
</a>\r
</a>\r\n

等等。

What I do is use a regex tester (whichever uses the same regex engine that you are using) and I test my pattern on it. I've tried using text editors that display invisible characters but to me they only add to the confusion.

So I just go by trial and error. For instance, if a line ends in:

</a>

Then I'll try the following patterns on the regex tester until I find one that works:

</a>.
</a>..
</a>\s
</a>\s*
</a>\n
</a>\r
</a>\r\n

Etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文