How to matching "[" in string


#1

Hi,

How to matching “[” in string with regular expressions?

“[” =~ /[/ – don’t work.


#2

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? :wink:

“[” =~ /[/ ? “It matched!” : “No match.”
=> “It matched!”

James Edward G. II


#3

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.


#4

Sorry and thx
I have expected 1, count of matching