Tokens
The FluentBuilder
must be initialized before using tokens. Use one of the above helper methods to do this. Tokens can be chained to create increasingly complex regular expressions.
anything
The anything
method matches any characters.
use Rudashi\Regex;
$pattern = Regex::build()->anything();
// /.*/
character
The character
method literally matches the given character.
use Rudashi\Regex;
$pattern = Regex::build()->character('-');
// /-/
and
The and
method is an alias for the character
method.
use Rudashi\Regex;
$pattern = Regex::build()->and('-');
// /-/
raw
The raw
method is an alias for the character
method.
use Rudashi\Regex;
$pattern = Regex::build()->raw('-');
// /-/
exactly
The exactly
method literally matches the given string.
use Rudashi\Regex;
$pattern = Regex::build()->exactly('foo');
// /foo/
Special characters are additionally escaped.
use Rudashi\Regex;
$pattern = Regex::build()->exactly('._%+-[]');
// /\._%\+\-\[\]/
find
The find
method is an alias for the exactly
method.
use Rudashi\Regex;
$pattern = Regex::build()->find('foo');
// /foo/
then
The then
method is an alias for the exactly
method.
use Rudashi\Regex;
$pattern = Regex::build()->then('foo');
// /foo/
letter
The letter
method matches any single letter, regardless of whether it is lowercase or uppercase.
use Rudashi\Regex;
$pattern = Regex::build()->letter();
// /[a-zA-Z]/
lowerLetter
The lowerLetter
method matches any single lowercase letter.
use Rudashi\Regex;
$pattern = Regex::build()->lowerLetter();
// /[a-z]/
number
The number
method matches any single number (equivalent to \d
).
use Rudashi\Regex;
$pattern = Regex::build()->number();
// /[0-9]/
numbers
The numbers
method matches all numbers.
use Rudashi\Regex;
$pattern = Regex::build()->numbers();
// /[0-9]+/
whitespace
The whitespace
method matches any whitespace character (equivalent to [\r\n\t\f\v ]).
use Rudashi\Regex;
$pattern = Regex::build()->whitespace();
// /\s/
nonWhitespace
The nonWhitespace
method matches any non-whitespace character.
use Rudashi\Regex;
$pattern = Regex::build()->nonWhitespace();
// /\S/
digit
The digit
method matches any single digit (equivalent to [0-9]).
use Rudashi\Regex;
$pattern = Regex::build()->digit();
// /\d/
digits
The digits
method matches all digits.
use Rudashi\Regex;
$pattern = Regex::build()->digits();
// /\d+/
nonDigit
The nonDigit
method matches any single character that is not a digit (equivalent to [^0-9]).
use Rudashi\Regex;
$pattern = Regex::build()->nonDigit();
// /\D/
nonDigits
The nonDigits
method matches all non-digit characters.
use Rudashi\Regex;
$pattern = Regex::build()->nonDigits();
// /\D+/
word
The word
method matches any word character (equivalent to [a-zA-Z0-9_]).
use Rudashi\Regex;
$pattern = Regex::build()->word();
// /\w/
words
The words
method matches all words characters.
use Rudashi\Regex;
$pattern = Regex::build()->words();
// /\w+/
boundary
The boundary method allows you to match only whole words without consuming any character (equivalent to (^\w |
\w$ | \W\w | \w\W)). |
use Rudashi\Regex;
$pattern = Regex::build()->boundary();
// /\b/
nonBoundary
The nonBoundary
method matches at every position where boundary
does not.
use Rudashi\Regex;
$pattern = Regex::build()->nonBoundary();
// /\B/
anyOf
The anyOf
method matches any single characters present in the given string.
use Rudashi\Regex;
$pattern = Regex::build()->anyOf('abc');
// /[abc]/
tab
The tab
method matches a tab character.
use Rudashi\Regex;
$pattern = Regex::build()->tab();
// /\t/
carriageReturn
The carriageReturn
method matches a carriage return.
use Rudashi\Regex;
$pattern = Regex::build()->carriageReturn();
// /\r/
newline
The newline
method matches a line-feed character (newline).
use Rudashi\Regex;
$pattern = Regex::build()->newline();
// /\r/
linebreak
The linebreak
method matches a carriage return or newline.
use Rudashi\Regex;
$pattern = Regex::build()->linebreak();
// /\r|\n/