Coder Social home page Coder Social logo

regexpbuilderphp's Issues

Start of group?

How is start of group calculated? Can I somehow explicitly mark the start of group?

escape delimiter when sanitizing strings

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.

Exact digits matching

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?

Match any 0+ of lineBreaks

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.

Groups & globalMatch() don't mix well

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?

Composer issue

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

Exact digits matching

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?

anyOf Method

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

Class 'Gherkins\RegExpBuilderPHP\RegExpBuilder' not found

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

Missing maintainer

Is there some maintainer for this package? I'd be happy to help to move it forward and upgrade to current PHP versions

How to get everything between tags

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();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google 鉂わ笍 Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.