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


i'm pretty new this, excuse me if question isn't clear. i'm pulling rss feed yahoo pipes , using regex modify it. here's i'm trying do:

  1. limit number of characters in entry, but...
  2. make sure item includes complete words, and...
  3. if item shortened, add ellipses, but...
  4. if falls within limits nothing should done

so, if feed's title is: "this article important" , limit 20 characters, result should "this article is..." if title "good article," nothing should happen it.

after doing research think want combine if/then statement lookahead, i.e. go character limit , if there character following space, add ellipses, if number or letter, go final space within limit , add ellipses, if there isn't character following it, don't anything. make sense? there easier way i'm going for?

i appreciate provide. thanks!

try replacing title using following pattern:

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

with string

$1... 

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

how work?

  • (?=.{23}) - first, check length @ least 23 (that's 20 + '...', can play that)
  • (.{0,20}) - match @ 20 characters on first group.
  • (?=\s) - make sure there's space after last character. if not, try match fewer characters.
  • .* - match way end, rest of line removed.

an edge case here single word longer 20 characters. if that's problem, can solve using:

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

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -