regexrssyahoo-pipes

How to Use Regex to Ensure Complete Words While Adding a Character Limit to Yahoo Pipes?


I'm pretty new to this, so excuse me if my question isn't that clear. I'm pulling an RSS Feed into Yahoo Pipes and using Regex to modify it. Here's what I'm trying to do:

  1. Limit the number of characters in an entry, but...
  2. Make sure the item includes complete words, and...
  3. If the item is shortened, add an ellipses, but...
  4. If it falls within the limits nothing should be done to it

So, if a feed's Title is: "This article is important" and the limit is 20 characters, the result should be "This article is..." But if the Title is "Good Article," nothing should happen to it.

After doing some research I think that I want to combine an if/then statement with lookahead, i.e. go to the character limit and if there is a character following it that is a space, add an ellipses, if it is a number or letter, go to the final space within the limit and add an ellipses, but if there isn't any character following it, don't do anything. Does this make sense? Is there an easier way to do what I'm going for?

I would really appreciate any help you could provide. Thanks!


Solution

  • Try replacing the title using the following pattern:

    ^(?=.{23})(.{0,20})(?=\s).*$
    

    With the string

    $1...
    

    Working example: http://pipes.yahoo.com/pipes/pipe.info?_id=04158a7a5ea390b1b0b78ebccadcec79

    How does it work?

    An edge case here is a single word longer than 20 characters. If that's a problem, you can solve it by using:

    ^(?=.{23})(.{0,20}(?=\s)|\S{20}).*$