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.
1cc0dba075e6d12b3f48fb3cb170f54a?d=identicon&s=25 sed_nivo (Guest)
on 2006-05-10 23:27
Hi,

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

 "[" =~ /\[/ -- don't work.
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-05-10 23: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 Gray II
2ffac40f8a985a2b2749244b8a1c4161?d=identicon&s=25 Mike Stok (Guest)
on 2006-05-10 23: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 Stok <mike@stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.
1cc0dba075e6d12b3f48fb3cb170f54a?d=identicon&s=25 sed_nivo (Guest)
on 2006-05-10 23:45
Sorry and thx
I have expected 1, count of matching
This topic is locked and can not be replied to.