gherkins / regexpbuilderphp Goto Github PK
View Code? Open in Web Editor NEW馃 human-readable regular expressions
License: MIT License
馃 human-readable regular expressions
License: MIT License
Coverage should be run only against php7
How is start of group calculated? Can I somehow explicitly mark the start of group?
iAMthePRONY via reddit
i would've change the "test" method name to something like "matches", or "doesMatch"
justaphpguy via reddit
I've seen only one usage of preg_quote() [1] in your source and in the test() [2] method uses the '/' delimiter. So, from the looks it seems you need to add the delimiter to preg_quote() otherwise your code can generate invalid regex.
feature to implement, see: http://stackoverflow.com/questions/6971287/named-capture-in-php-using-regex
I may do a PR, if you have any recommendations, please share
I'm trying to match expression with exactly 10 digits. Maybe I don't understand it correctly, so here is my example:
$regExp = (new RegExpBuilder)->exactly(10)->digits()->getRegExp();
var_dump($regExp->test(123456789)); // should: FALSE, is FALSE
var_dump($regExp->test(1234567890)); // should: TRUE, is TRUE
var_dump($regExp->test(12345678901)); // should: FALSE, is TRUE
How to achieve my goal?
Update: found a solution, is it proper?
I would like to match these cases:
- <code>hello</code>
- <code>hello
</code>
So I've created builder like this:
$surroundingTagRegExpWithLineBreaks = (new RegExpBuilder)->startOfInput()
->find(sprintf('<%s', $tag))
->anything()
->min(0)->lineBreaks()
->find(sprintf('</%s>', $tag))
->endOfInput()
->getRegExp();
I'd expect ->min(0)->lineBreaks()
to compatible with ->any()->lineBreaks()
. But it isn't.
Can I use back references? I cannot seem to find it in the docs.
The group matches are ignored when adding globalMatch flag.
$builder = new RegExpBuilder();
$regExp = $builder->getNew()->globalMatch()
->then('Foo of ')
->append($builder->getNew()->anythingBut(' '))
->asGroup()
->getRegExp();
$string = 'Foo of Bar Foo of Dummy';
$output = $regExp->findIn($string);
outputs this, where can see that group matches is missing:
array (2)
路 [0]: string (10) "Foo of Bar"
路 [1]: string (12) "Foo of Dummy"
So I added one more condition to RegExp.php:114
:
if (!isset($matches[1]) && isset($matches[0]) && is_array($matches[0])) {
return $matches[0];
}
tests pass and it outputs this now:
路 [0]: array (2)
路 路 [0]: string (10) "Foo of Bar"
路 路 [1]: string (12) "Foo of Dummy"
路 [1]: array (2)
路 路 [0]: string (3) "Bar"
路 路 [1]: string (5) "Dummy"
Should I make a PR?
Hi,
when you ship this (great, by the way) project to Packagist, could you remove the .git directory. It messes up my git installation by making your code as a submodule of my code that I have many pains to push.
Each time I update I need to manually remove your .git directory, add all your files to my change list and then I can commit.
Thanks
I'm trying to match expression with exactly 10 digits. Maybe I don't understand it correctly, so here is my example:
$regExp = (new RegExpBuilder)->exactly(10)->digits()->getRegExp();
var_dump($regExp->test(123456789)); // should: FALSE, is FALSE
var_dump($regExp->test(1234567890)); // should: TRUE, is TRUE
var_dump($regExp->test(12345678901)); // should: FALSE, is TRUE
How to achieve my goal?
Is that a feature or you've just forgotten?
adrianmiu via reddit
I would change
->eitherFind("png")->orFind("jpg")->orFind("gif")
to something like
->anyOf(array('png', 'jpg', 'gif'))
or something to that extent
I just downloaded your repo using composer require gherkins/regexpbuilderphp and started soing some tests as suggested by you. i have created new test.php file under regexpbuilderphp folder
<?php
namespace Gherkins\RegExpBuilderPHP;
$builder = new \Gherkins\RegExpBuilderPHP\RegExpBuilder();
$regExp = $builder
->startOfInput()
->exactly(4)->digits()
->then("_")
->exactly(2)->digits()
->then("_")
->min(3)->max(10)->letters()
->then(".")
->anyOf(array("png", "jpg", "gif"))
->endOfInput()
->getRegExp();
//true
$regExp->matches("2020_10_hund.jpg");
$regExp->matches("2030_11_katze.png");
$regExp->matches("4000_99_maus.gif");
//false
$regExp->matches("123_00_nein.gif");
$regExp->matches("4000_0_nein.pdf");
$regExp->matches("201505_nein.jpg");
but i am getting error saying:
Fatal error: Class 'Gherkins\RegExpBuilderPHP\RegExpBuilder' not found in C:\wamp\www\gherkins\regexpbuilderphp\src\test.php on line 5
can you please help.
thanks
Is there some maintainer for this package? I'd be happy to help to move it forward and upgrade to current PHP versions
what's the difference?
I need to get something between to tag (match, but excluding). How to do so?
I've stared with:
$surroundingTag = (new RegExpBuilder)->startOfInput()
->find('<p>')
->anything() // I need this content
->find('</p>')
->endOfInput()
->getRegExp();
A declarative, efficient, and flexible JavaScript library for building user interfaces.
馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google 鉂わ笍 Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.