Regex to leave desired string remaining and others removed

Posted by m7d on Stack Overflow See other posts from Stack Overflow or by m7d
Published on 2011-02-01T07:00:23Z Indexed on 2011/02/01 15:25 UTC
Read the original article Hit count: 612

Filed under:
|
|

In Ruby, what regex will strip out all but a desired string if present in the containing string? I know about /[^abc]/ for characters, but what about strings?

Say I have the string "group=4&type_ids[]=2&type_ids[]=7&saved=1" and want to retain the pattern group=\d, if it is present in the string using only a regex?

Currently, I am splitting on & and then doing a select with matching condition =~ /group=\d/ on the resulting enumerable collection. It works fine, but I'd like to know the regex to do this more directly.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about regex