Download the PHP package iak/regexbuilder without Composer
On this page you can find all versions of the php package iak/regexbuilder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download iak/regexbuilder
More information about iak/regexbuilder
Files in iak/regexbuilder
Package regexbuilder
Short Description A simple regex pattern builder inspired by eloquent
License MIT
Informations about the package regexbuilder
Regex builder
A fluent api that simplifies writing regular expressions. (for the ones of us who always forget the syntax)
Installation
Grab it using composer
Simple as that :)
Introduction
This library is for all of us that find regular expressions hard to write and impossible to remember all the different flags, look aheads, capture groups etc.
Instead of spending that half hour searching stackoverflow, I hope you can easily whip up a pattern using this lib.
Note. a basic understading of how regular expressions is still needed.
Quick start
First of all, use the class at the top of you file,
Now you can use it like this
Or maybe something more advanced (and demostrating some different ways of using the library)
Documentation
Words, patterns and symbols
word(mixed $word = null)
Matches provided word, array of words or any word
notWord()
Matches anything but a word
symbols(string $symbols)
Matches provided symbols (escapes string, if you don't want that, use "pattern")
pattern(string $pattern)
Matches provided pattern
Aliases: raw()
Characters
You can match a bunch of characters using the following helper methods
Quantifiers
oneOrMore()
Matches one or more of preceding group, character or character set.
zeroOrMore()
Matches zero or more
count(int $count/$start, int $end = null)
Matches the specified amount or the minimum and maximun count
Groups & Character sets
range(mixed $start, $mixed $end)
Specifies a range, made especially for working with character sets
group(mixed $pattern/$callback)
Creates a character set
Capture groups
capture(callable $callback = null)
Creates a capture group
opionalCapture(mixed $pattern/$callback)
Creates a non capturing group
startCapture() and endCapture()
You can also surround what you want to capture with these methods
Look aheads & look behinds
behind(mixed $pattern/$callback)
Creates a look behind
Aliases: beginsWith(), before()
after(mixed $pattern/$callback)
Creates a look ahead, works exactly like before()
Aliases: endsWith()
Other helpers
optional(mixed $characters/$start = null, $length = null)
Makes capture group, character set or character optional
escape(string $pattern)
Escapes provided pattern
getPattern()
Returs the built up pattern
release()
Removes built up pattern
Matching and replacing
replace($string, $subject)
Replace built up pattern with provided string
match($string)
Matches the first occurrence of the built up pattern
Note! only return the match. If you want all capture groups, use matchWithGroups()
matchAll($string)
Matches all of the occurences of the built up pattern
Note! only return the match. If you want all capture groups, use matchAllWithGroups()