ClassIP
Include regexpbuilder
DefLess_than_255
_ 0_to_100 = repeat (digit (),1,2)
_ 100_to_200 = "1" + _ 0_to_100
_ 200_to_250 = "2" + either ("0-4") + either ("0-9 ")
_ 250_to_255 = "25" + either ("0-4 ")
One_of (_ 0_to_100, _ 100_to_200, _ 200_to_250, _ 250_to_255)
End
DefInitialize
@ Ip_pattern= Repeat (group (less_than_255 () + literal (".")),3) + Group (less_than_255 ())
End
Attr_reader: Ip_pattern
End
The above is an example of using regexbuilder to write a regular expression, such as an IP address.
Regexbuilder is designed to enhance the readability and maintainability of regular expressions.
Regexbuilder is not used to replace Regexp, but to help compile the first parameter required by the Regexp constructor.
Regexbuilder contains a one-to-one correspondence between regular expression symbols (anchors/character classes/repetition/alternation/grouping) and APIs, such as one_of = >|, either => [], at_least_one => +.
Regexbuilder also contains a set of common regular expressions that can be directly used, such as IP addresses and email addresses.
Regexbuilder uses Java APIs instead of Ruby APIs, such as repeat (3, Digit () instead of digit (:Repeat=>3)
Regexbuilder has not implemented substitutions, such as/0,/1.
Install and download
Gem install regexbuilder
Http://roll-stone.googlecode.com/svn/trunk/RegexBuilder/
It is an example of using regexbuilder to create regular expression like IP address.
Regexbuilder tries to improve the readability and maintainability of regular expression.
Regexbuilder does not intend to replace the Regexp class, while it just helps to create the first parameter of the ctor of Regexp.
Regexbuilder maps the symbols of regular expression (anchors/character classes/repetition/alternation/grouping) to API, like one_of => |, either => [], at_least_one => +, etc.
Regexbuilder supports a group of regular expression which are used frequently, such as IP and email address.
Regexbuilder uses Java style API rather than Ruby style API, like repeat (3, Digit (), but not digit (:Repeat=>3)
Regexbuilder does not support substitutions for now, like/0,/1,/& etc.
Download and install
Gem install regexbuilder
Http://roll-stone.googlecode.com/svn/trunk/RegexBuilder/