ruby on rails - How can I cut only necessary part of string in RoR? -
for exsmple:
i have: new.string-@22/4576/:thisneedtoo.ffgfhha.pdf?7765trimsaskellyo2212
and need only: string-@22/4576/:thisneedtoo.ffgfhha.pdf?
if string starts "new.", , want after , including question mark, simple ruby regular expression pull out:
match_data = /\anew\.([^?]+\?).+\z/.match(s) match_data[1] => "string-@22/4576/:thisneedtoo.ffgfhha.pdf?"
i start easy-to-understand regular expression , once working, refine , optimize expression , add error checking.
Comments
Post a Comment