Adding \wcf\system\Regex
authorTim Düsterhus <timwolla@arcor.de>
Sat, 17 Dec 2011 12:39:32 +0000 (13:39 +0100)
committerTim Düsterhus <timwolla@arcor.de>
Sat, 17 Dec 2011 12:47:23 +0000 (13:47 +0100)
commitac9b0f6e74ed0eba56df3bf0385f48d9aec0c9da
tree02508ec743ee63cdaf8644ace7cb0444f2497f78
parente7438c3241ceb6809cf92e32a12214799f01dc2e
Adding \wcf\system\Regex

That way we can typehint regexes and have object-oriented access on regexes.

There is no longer a need to add or escape the delimiters, this is all done by the Regex-class.
The modifiers are added via a bitmask as the second parameter:
Valid modifiers are:
Regex::CASE_INSENSITIVE (add i)
Regex::EVAL_REPLACEMENT (add e)
Regex::UNGREEDY (add U)
Regex::NO_ANALYSE (don't add s)

Usage:

```
$regex = new Regex('^http(s)?://(www\.)woltlab\.(com|de|info)/', Regex::CASE_INSENSITIVE);
var_dump($regex->match('http://www.woltlab.com/pluginstore/')); // int(1)
var_dump($regex->getMatches()); // array with all matched substrings

var_dump(Regex::compile('[a-z]')->replace('asdf345', '')); // string(3) "345"
var_dump(Regex::compile('[a-z]')->replace('asdf345', new Callback(function ($matches) {
return 'x';
})); // string(7) "xxxx345"
```
wcfsetup/install/files/lib/data/language/LanguageEditor.class.php
wcfsetup/install/files/lib/data/template/TemplateEditor.class.php
wcfsetup/install/files/lib/system/Regex.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/WCFSetup.class.php
wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php
wcfsetup/install/files/lib/system/template/TemplateEngine.class.php
wcfsetup/install/files/lib/util/DirectoryUtil.class.php