Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Commit

Permalink
Fix regexify on PHP 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Nov 7, 2014
1 parent 430c066 commit bd42144
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Faker/Provider/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,15 @@ public static function regexify($regex = '')
return static::randomElement(str_split($matches[1]));
}, $regex);
// replace \d with number and \w with letter and . with ascii
$regex = preg_replace_callback('/\\\w/', 'static::randomLetter', $regex);
$regex = preg_replace_callback('/\\\d/', 'static::randomDigit', $regex);
$regex = preg_replace_callback('/(?<!\\\)\./', 'static::randomAscii', $regex);
$regex = preg_replace_callback('/\\\w/', function() {
return static::randomLetter();
}, $regex);
$regex = preg_replace_callback('/\\\d/', function() {
return static::randomDigit();
}, $regex);
$regex = preg_replace_callback('/(?<!\\\)\./', function() {
return static::randomAscii();
}, $regex);
// remove remaining backslashes
$regex = str_replace('\\', '', $regex);
// phew
Expand Down

0 comments on commit bd42144

Please sign in to comment.