开发者

Regular expression in Yahoo Pipes

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.开发者_StackOverflow

Thanks


Match

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

with

$1


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

  • pipes.yahoo.com - Regex module documentation - has a very good tutorial
  • regular-expressions.info - a more comprehensive regex tutorial

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜