Skip to content

Instantly share code, notes, and snippets.

@Mikulas
Created July 27, 2010 19:21
Show Gist options
  • Save Mikulas/492710 to your computer and use it in GitHub Desktop.
Save Mikulas/492710 to your computer and use it in GitHub Desktop.
Regex Wrapper example usage
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Regex Sandbox with default Unicode support</title>
</head>
<body style="font-family: Verdana; ">
<h1 style="font-size: 23px;">Regex class with unicode support and objective access</h1>
<?php
require_once 'RegexWrapper.php';
use Wrapper\Regex;
$subject = 'Mikuláš';
$pattern = 'Mikul(?P<singleChar>.)š';
$r = new Regex();
$r->setPattern($pattern);
$r->setSubject($subject);
$r_res = $r->match()->singleChar;
$s = new Regex();
$s_res = $s->match($subject, $pattern)->singleChar;
// $r_res === $s_res
?>
Subject:
<?php var_dump($subject) ?>
Regex:
<?php var_dump($r->getRegex()) ?>
Match for &lt;singleChar&gt;:
<?php var_dump($r_res) ?>
<hr>
Code:<br>
<code>
$r = new Regex();<br>
$r->setPattern('Mikul(?P<singleChar>.)š');<br>
$r->setSubject('Mikuláš');<br>
$res = $r->match()->singleChar;<br>
</code><br>
or shorter<br>
<code>
$r = new Regex();<br>
$res = $r->match('Mikuláš', 'Mikul(?P<singleChar>.)š')->singleChar;<br>
</code>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment