Regular expressions in Ruby

I’m new to Ruby, and just want to ask about how to read the following
statement from the “Agile Web D. With Rails, 3rd edition” book:

%r{.(gif|jpg|png)$}i

I knew that %r is a way to write a regular expression.

But, what is the $, and the i?

Thanks.

Abder-rahman Ali wrote:

%r{.(gif|jpg|png)$}i

I knew that %r is a way to write a regular expression.

But, what is the $, and the i?

http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html#UK

Brian C. wrote:

Abder-rahman Ali wrote:

%r{.(gif|jpg|png)$}i

I knew that %r is a way to write a regular expression.

But, what is the $, and the i?

http://www.ruby-doc.org/docs/ProgrammingRuby/html/language.html#UK

Thanks Brian.

On Mon, Jun 14, 2010 at 5:24 PM, Abder-rahman Ali
[email protected] wrote:

I’m new to Ruby, and just want to ask about how to read the following
statement from the “Agile Web D. With Rails, 3rd edition” book:

%r{.(gif|jpg|png)$}i

I knew that %r is a way to write a regular expression.

But, what is the $, and the i?

I always have this link handy:

http://www.zenspider.com/Languages/Ruby/QuickRef.html#11

$ matches the end of a line or string
i is a modifier that makes the regexp case insensitive.

Jesus.

On Mon, Jun 14, 2010 at 10:24 AM, Abder-rahman Ali <
[email protected]> wrote:

I’m new to Ruby, and just want to ask about how to read the following
statement from the “Agile Web D. With Rails, 3rd edition” book:

%r{.(gif|jpg|png)$}i

It matches a dot, followed by either gif or jpg or png, at the end of
the
string. It does not care about case.

For example, it would match

foo.gif
foo.GiF
fOoO.jpg
bar.PNG

It would not match

foogif
foo.gif.
foo.giff
foo.jp
foo.pjg
foo.jpx
foo.jpg.csv

On Mon, Jun 14, 2010 at 12:24 PM, Abder-rahman Ali
[email protected] wrote:

I’m new to Ruby, and just want to ask about how to read the following
statement from the “Agile Web D. With Rails, 3rd edition” book:

%r{.(gif|jpg|png)$}i

I knew that %r is a way to write a regular expression.

But, what is the $, and the i?

$ matches the end of the string and i makes the search case
insensitve. This is not Ruby specific, perphaps you should read about
regular expressions. See http://www.regular-expressions.info/ruby.html

Bye

After referring to the regular expressions references provided, test
them out at rubular.com.

But, what is the $, and the i?
-> http://rubular.com/ -> Regex quick reference

The \ escapes the . Thus . matches the ‘.’ character.

Marc W.

I suppose this shall help
http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm


Thanks and Regards
Saurabh P.
+91-9922071155
skype: sorab_pune
yahoo & gtalk: saurabh.purnaye
msn: [email protected]

please don’t print this e-mail unless you really need to.

On Mon, Jun 14, 2010 at 8:54 PM, Abder-rahman Ali <