Forum: Ruby how i can get value in string with pattern

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jakov (Guest)
on 2006-04-18 13:42
how i can get value in string with pattern or regular experssion

I have this string:

"Who is this (//mystring//)".gsub(?, "")

How i can get 'mystring' if it's conclude in mystring.
Alder G. (Guest)
on 2006-04-18 13:54
(Received via mailing list)
"Who is this (//mystring//)".scan(Regexp.new('//(.*)//')).first.first
#=> "mystring"
Robert K. (Guest)
on 2006-04-18 13:57
(Received via mailing list)
2006/4/18, Jakov <removed_email_address@domain.invalid>:
> how i can get value in string with pattern or regular experssion
>
> I have this string:
>
> "Who is this (//mystring//)".gsub(?, "")
>
> How i can get 'mystring' if it's conclude in mystring.

p "Who is this (//mystring//)".scan(%r{//(\w+)//}).map{|m| m[0]}

s = %r{//(\w+)//} =~ "Who is this (//mystring//)" && $1
p s

Cheers

robert
Jakov (Guest)
on 2006-04-18 14:17
thanks, for all
This topic is locked and can not be replied to.