PHP Classes

File: tests/groups.php

Recommend this page to a friend!
  Classes of Patrick Van Bergen  >  PHP Regex Builder  >  tests/groups.php  >  Download  
File: tests/groups.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Regex Builder
Generate regular expression strings from rules
Author: By
Last change:
Date: 5 years ago
Size: 1,292 bytes
 

Contents

Class file image Download
<?php

// empty group
test('/()/',
   
R::expression()->group(R::group())
);

// named group
test('/(?P<protocol>)/',
   
R::expression()->group(R::group('protocol'))
);

// some quantifier: one or more
test('/(very)+/',
   
R::expression()->group(
       
R::group()->oneOrMore()->text('very')
    )
);

// dot
test('/(.)/',
   
R::expression()->group(R::group()->char(R::anyChar()))
);

// or
test('/(master|maestro|mister)/',
   
R::expression()->group(R::group()->oneOfThese()->text('master')->text('maestro')->text('mister'))
);
test('/(master|maestro|mister)/',
   
R::expression()->raw('(master|maestro|mister)')
);

// quantifier: optional
test('/(nom)?/',
   
R::expression()->group(R::group()->optional()->text('nom'))
);

// wordBoundary
test ('/(\b)/',
   
R::expression()->group(R::group()->wordBoundary())
);

// anythingButWordBoundary
test ('/(\B)/',
   
R::expression()->group(R::group()->anythingButWordBoundary())
);

// dontCapture
test ('/(?:abc)/',
   
R::expression()->group(R::group()->dontCapture()->text('abc'))
);

// startOfLine
test('/(^)/',
   
R::expression()->group(R::group()->startOfLine())
);

// endOfLine
test('/($)/',
   
R::expression()->group(R::group()->endOfLine())
);

// backReference
test('/(abc) \1/',
   
R::expression()
        ->
group(R::group()->text('abc'))
        ->
text(' ')
        ->
backReference(1)
);

For more information send a message to info at phpclasses dot org.