Forum: Ruby How to matching "[" in string

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.
sed_nivo (Guest)
on 2006-05-11 01:27
Hi,

How to matching "[" in string with regular expressions?

 "[" =~ /\[/ -- don't work.
James G. (Guest)
on 2006-05-11 01:34
(Received via mailing list)
On May 10, 2006, at 4:27 PM, sed_nivo wrote:

> Hi,
>
> How to matching "[" in string with regular expressions?
>
>  "[" =~ /\[/ -- don't work.

Says who?  ;)

 >> "[" =~ /\[/ ? "It matched!" : "No match."
=> "It matched!"

James Edward G. II
Mike S. (Guest)
on 2006-05-11 01:38
(Received via mailing list)
On 10-May-06, at 5:27 PM, sed_nivo wrote:

> How to matching "[" in string with regular expressions?
>
>  "[" =~ /\[/ -- don't work.

What do you mean by "don't work"?  What do you expect?  Have you read
the documentation for String#=~?

ratdog:~ mike$ irb
irb(main):001:0> "[" =~ /\[/
=> 0
irb(main):002:0> "x" =~ /\[/
=> nil
irb(main):003:0> "this[that]" =~ /\[/
=> 4

Mike

--

Mike S. <removed_email_address@domain.invalid>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.
sed_nivo (Guest)
on 2006-05-11 01:45
Sorry and thx
I have expected 1, count of matching
This topic is locked and can not be replied to.