Recommend this page to a friend! |
![]() ![]() |
Info | ![]() |
![]() |
![]() ![]() |
Reputation | Support forum (2) | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 174 This week: 1 | All time: 8,639 This week: 289![]() |
Version | License | PHP version | Categories | |||
regexp-r 1.0.0 | MIT/X Consortium ... | 5 | PHP 5, Text processing |
Description | Author | |
This class can generate regular expression strings from rules. |
r Is a PHP library to build regular expressions.
It is written for PHP 5 and it handles PCRE patterns in a fairly advanced level, but it does not cover the complete specification.
There are several reasons why one would want build a regular expression with code, rather than to write it down directly:
* For non-experts, the expression is easier to read * It is a handy tool to compose an expression at runtime, depending on different variables and rules * There is no need to escape characters, which is always a tricky part * No need to look up the syntax of little used constructs: the fluid interface allows for auto completion
These examples can also be found in the file 'examples.php'.
/^Paradise Lost$/
R::expression()
->startOfString()
->text('Paradise Lost')
->endOfString()
/The (dog|cat)?basket fell off the roof/
R::expression()
->text('The ')
->group(
R::group()->optional()->oneOfThese()->text('dog')->text('cat')
)
->text('basket fell off the roof')
/the [bc]?old man and the [^c]ee.*/
R::expression()
->text('the ')
->inChars(R::chars('bc')->optional())
->text('old man and the ')
->notInChars(R::chars('c'))
->text('ee')
->char(R::anyChar()->zeroOrMore())
/(<a href='([^']*)'>)/
R::expression()
->group(
R::group()
->text("<a href='")
->group(
R::group()
->notInChars(R::chars("'")->zeroOrMore())
)
->text("'>")
)
/\bkettle\b/
R::expression()
->wordBoundary()
->text('kettle')
->wordBoundary()
/[\d]{4}[a-z]{2}/
R::expression()
->char(R::chars()->digit()->times(4))
->char(R::chars()->letter()->times(2))
#(?P<protocol>http[s]?)://(?P<url>.*)#
R::expression()
->group(
R::group('protocol')
->text('http')
->char(R::chars('s')->optional())
)
->text('://')
->group(
R::group('url')
->char(R::anyChar()->zeroOrMore())
)
/^start\s+(^the)\s+show$/m
R::multiLineExpression()
->startOfStringOrLine()
->text('start')
->whitespace()
->group(
R::group()->startOfLine()->text('the')
)
->whitespace()
->text('show')
->endOfStringOrLine()
/(?<=Lord )(Byron)/
R::expression()
->lookBehind(
R::lookBehind()->text('Lord ')
)
->group(
R::group()->text('Byron')
)
Then write parts of the expression in the old style:
#(?P<protocol>https?)://(?P<url>.*)#
R::expression()
->group(
R::group('protocol')->raw('https?')
)
->text('://')
->group(
R::group('url')->raw('.*')
)
The credits for the idea of creating a regular expression builder go to VerbalExpressions. It is a fascinating idea and I wanted to see how far it could go. I chose a different type of implementation based on nested fluid interface calls.
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() |
||||
![]() ![]() |
Example | Example script | ||
![]() ![]() |
Lic. | License text | ||
![]() |
Class | Class source | ||
![]() ![]() |
Doc. | Documentation | ||
![]() ![]() |
Aux. | Auxiliary script |
![]() |
/ | components |
File | Role | Description |
---|---|---|
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
Class | Class source |
![]() |
/ | tests |
File | Role | Description |
---|---|---|
![]() ![]() |
Example | Example script |
![]() ![]() |
Example | Example script |
![]() ![]() |
Example | Example script |
![]() ![]() |
Example | Example script |
![]() ![]() |
Example | Example script |
![]() ![]() |
Example | Example script |
![]() ![]() |
Example | Example script |
![]() ![]() |
Example | Example script |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
User Comments (1) | |||||
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.