regex - Rails: truncate string after match -


say i've got string so:

"this belongs there's other keyword else." 

how truncate it'd find keyword , truncate keyword else. give me only:

"this belongs there's other " 

thanks!

1.9.3p327 > str = "this belongs there's other keyword else."  => "this belongs there's other keyword else." 1.9.3p327 > str.sub(/keyword.*/, '')  => "this belongs there's other " 

be careful though match on "keywordwithnotrailingspace". \b getting word boundaries...


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -