Jaskaran
Jaskaran

Reputation: 188

regular expression in ruby and rails

Is regular expression syntax symbol are same in every language or any change. I am learning ruby and rails and I am reading this book http://www.railstutorial.org/book/

In this book writer use regular expression and i want to know is it different in ruby or rails or same like other languages ?

Please help me

Upvotes: 0

Views: 147

Answers (3)

canoe
canoe

Reputation: 1293

It really depends on the regular expression engines adopted by a programming language. They all should comply with the POSIX standards or some other specific extensions. So basically, they are pretty much of the same.

Ruby(1.9) supports GNU regex, POSIX and Oniguruma native. For details difference between lanagues, search Comparison_of_regular_expression_engines#Language_features on wikipedia.

Upvotes: 0

theftprevention
theftprevention

Reputation: 5213

Ruby's regular expressions function in much the same way as Perl. Some special notes:

In Ruby, the caret and dollar always match before and after newlines. Ruby does not have a modifier to change this. Use \A and \Z to match at the start or the end of the string.

Much like JavaScript, you can create a Regexp object with literal notation:

myRegExp = /test/i

Ruby's implementation mostly differs in the methods and operators available on Regexp objects.

More information about Ruby's implementation of regular expressions is available here.

Upvotes: 2

HandDisco
HandDisco

Reputation: 627

The fundamentals are the same but there can be discrepancies between languages. Here's a good site for ruby regex http://rubular.com/

Upvotes: 0

Related Questions