PHP Classes

File: tests/word_pairs.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of Marco Marchiņ  >  Regexp Builder  >  tests/word_pairs.php  >  Download  
File: tests/word_pairs.php
Role: Example script
Content type: text/plain
Description: Word pairs match
Class: Regexp Builder
Build regular expressions programmatically
Author: By
Last change:
Date: 5 years ago
Size: 1,026 bytes


Class file image Download
require_once "../regexpBuilder.php";
Word pair test. Find the first word in a sequence of equal words.
Format: test test test FOO FOO
- start capture the first word
- letter characters repeated one or more times
- end capture
- open a group
- space character
- match the first word captured
- close group and match only if it is repeated one ore more times

$regexp=new regexpBuilder();
$regexp->capture("first word") //Start a capture and assign it a name
->match(LETTER_CHAR)->frequency(ONE_OR_MORE) //letter characters repeated one or more times
->closeCapture() //end capture
->openGroup() //open a group
->match(SPACE_CHAR) //space character
->matchCapture("first word") //match the first word captured
->closeGroup()->frequency(ONE_OR_MORE); //close group and repeat it one ore more times

$match=$regexp->execOn("test test test FOO FOO",PREG_SET_ORDER);
"test test test FOO FOO<br>Match 1: ".$match[0][1]."<br>"."Match 2: ".$match[1][1]; //Match 1: test, Match 2:FOO