Yahoo Pipes 中的正则表达式

发布于 2024-09-16 02:15:48 字数 110 浏览 2 评论 0原文

我想知道应该应用什么正则表达式来替换 1 - 55 of 55 以仅在 yahoo Pipes 的 Regex 模块中获取 55

谢谢

I want to know what regular expression should be applied to replace 1 - 55 of 55 to only get 55 in Regex module of yahoo pipes.

Thanks

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

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

发布评论

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

评论(2

初见终念 2024-09-23 02:15:48

匹配

\d+ - (\d+) of \1 

$1

Match

\d+ - (\d+) of \1 

with

$1
金橙橙 2024-09-23 02:15:48

你可以尝试匹配这个:

\d+ - (\d+) of \1

并替换为$1,这是第1组捕获的内容。

\d 是数字字符类 + 是一个或多个重复(…) 是一个捕获组 \1 引用该组匹配的内容。因此,这将匹配如下字符串:

num1 - num2 of num2
        |        |
        \________/ must match

References


教程

此模式稍作修改,在空格匹配方面更加灵活:

\d+\s+-\s+(\d+)\s+of\s+\1

它与之前的模式类似,但之前只要有文字空格字符,现在就使用 \s+,这是一种模式匹配任意数量的空白字符的非空序列。这包括换行符、制表符等。

如果第三个数字不必与第二个数字相同,则只需使用另一个 \d+ 而不是 \1

\d+\s+-\s+\d+\s+of\s+(\d+)

现在,这将匹配像 "1 - 20 of 149" 这样的字符串,并且间距宽松。现在,括号已移动以匹配第三个数字,因此如果要将整个字符串替换为该数字(本例中为 149),只需替换为 $1 即可。

如果你想单独捕获所有 3 个数字,你可以这样写:

(\d+)\s+-\s+(\d+)\s+of\s+(\d+)
\___/       \___/        \___/
  1           2            3

现在第一个数字由组 1 捕获,第二个数字由组 2 捕获,第三个数字由组 3 捕获。

You can try to match this:

\d+ - (\d+) of \1

And replace with $1, which is what group 1 captured.

The \d is the digit character class, + is one-or-more repetition. The (…) is a capturing group, and the \1 refers back to what that group matches. So this will match strings like:

num1 - num2 of num2
        |        |
        \________/ must match

References


Variation

This pattern is a slight modification that is more flexible in its whitespace matching:

\d+\s+-\s+(\d+)\s+of\s+\1

It's similar to the previous pattern, but wherever we had just a literal space character before, we now use \s+, which is a pattern that matches a non-empty sequence of any number of whitespace characters. This includes newlines, tabs, etc.

If the third number doesn't have to be the same as the second number, then simply use another \d+ instead of \1.

\d+\s+-\s+\d+\s+of\s+(\d+)

Now this will match strings like "1 - 20 of 149", being liberal with the spacing. The bracket is now moved to match the third number, so if the entire string is to be replaced by that number (149 in this case), simply replace with $1.

If you want to capture all 3 numbers individually, you can write something like this:

(\d+)\s+-\s+(\d+)\s+of\s+(\d+)
\___/       \___/        \___/
  1           2            3

Now the first number is captured by group 1, second number by group 2, and third number by group 3.

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