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

Add regexify formatter #453

Merged
merged 2 commits into from
Nov 7, 2014
Merged

Add regexify formatter #453

merged 2 commits into from
Nov 7, 2014

Conversation

fzaninotto
Copy link
Owner

Transforms a basic regular expression into a random string satisfying the expression.

$faker->regexify('[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}'); // sm0@y8k96a.ej

Regex delimiters '/.../' and begin/end markers '^...$' are ignored.

Only supports a small subset of the regex syntax. For instance, unicode, negated classes, unbouned ranges, subpatterns, back references, assertions, recursive patterns, and comments are not supported. Escaping support is extremely fragile. See icomefromthenet/ReverseRegex for a more robust implementation.

This method is also VERY slow. Use it only when no other formatter can generate the fake data you want. For instance, prefer calling $faker->email rather than regexify with the previous regular expression.

Also note than bothify can probably do most of what this method does, but much faster. For instance, for a dummy email generation, try $faker->bothify('?????????@???.???').

@ronanguilloux
Copy link
Contributor

greeeeeat!

fzaninotto added a commit that referenced this pull request Nov 7, 2014
@fzaninotto fzaninotto merged commit 1c5fd3e into master Nov 7, 2014
@fzaninotto fzaninotto deleted the regexify branch November 7, 2014 08:35
@fzaninotto fzaninotto mentioned this pull request Nov 11, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants