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

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

java - SmsManager sending message more than one -