Way to partialy match a Ruby string using Regexp

Posted by Fabiano PS on Stack Overflow See other posts from Stack Overflow or by Fabiano PS
Published on 2010-04-28T17:09:53Z Indexed on 2010/04/28 17:13 UTC
Read the original article Hit count: 196

Filed under:
|
|

I'm working on 2 cases:

assume I have those var:

a = "hello"
b = "hello-SP"
b = "not_hello"

1 - Any partial matches

I want to accept any string that has the var a inside, so b and c would match.

2 - Patterned match

I want to match a string that has a inside, followed by '-', so b would match, c does not.

I am having problem, because I always used the syntax /expression/ to define Regexp, so how dinamicaly define an RegExp on Ruby??

© Stack Overflow or respective owner

Related posts about ruby

Related posts about string