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 -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -