Regexbuilder: a DSL for creating regular expression, request for comment

Source: Internet
Author: User
Tags alternation character classes repetition

 

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.