2017 © Pedro Peláez
 

library regular

A wrapper around PHP regexps

image

nourdine/regular

A wrapper around PHP regexps

  • Friday, June 17, 2016
  • by nourdine
  • Repository
  • 1 Watchers
  • 0 Stars
  • 23 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Regular

This library is an object oriented wrapper around the PHP regular expression function preg_match., (*1)

Examples

$haystack = "Can a url be detected inside this string? Who knows! www.nourdine.net... maybe so?!";
$regexp = new regular\Regular("/www.([a-z]{1,}).(com|net|org)/");
$match = $regexp->match($haystack);
$whole = $match->getWholeMatch();
$domainName = $match->getCaptured(0);
$domainExtension = $match->getCaptured(1);

The match variable contains an instance of regular\Match which we can use to obtain the actual whole match and the capturing groups, if any (see example above)., (*2)

In turn Match::getWholeMatch and Match::getCaptured return an instance of regular\Group which gives us access to the value of the match (being it a whole one or a sub-group) and its offeset:, (*3)

$whole->getValue(); // www.nourdine.net
$whole->getOffset(); // 53
$domainName->getValue(); // nourdine
$domainName->getOffset(); // 57
echo $domainExtension->getValue(); // net
echo $domainExtension->getOffset(); // 68

The Versions

17/06 2016

dev-master

9999999-dev

A wrapper around PHP regexps

  Sources   Download

GNU GPL V3

The Requires

  • php >=5.3

 

by Avatar nourdine

regexp