Yeah, I totally understand. Regular Expressions are a beast! ;)
I am not so sure that there would be a lot of people using this feature anyway.
What would really be nice is the wildcard support I guess.
I wonder whether it would make sense to enable simple wildcard support (
*) on the individual fields. This could be done by using regex internally.
You don't really need to understand the detailed syntax of regular expressions to use them to implement wildcard support.
The concept is as follows:
1. Take the user input and run it through preg_quote - this will put a backslash in front of every character that is part of the regex syntax
$input = preg_quote($input);
2. Then use str_replace to turn all wildcards into the correct regex syntax - the wildcard
* should match any character, which in regex syntax is
.* (dot means any character, and asterix means 0 or more times). We have to consider that in step 1. all asterix wildcards have been prefixed with a backslash
$input = str_replace("\\*", ".*", $input);
3. Then add a
^ at the beginning and a
$ at the end. These are the regex markers for line beginning and line ending.
I am still reflecting on whether there are better solutions. I had a look around (google) to see if there are any PHP projects or libs out there which have implemented something similar. Sometimes it's better not to reinvent the wheel. But haven't found anything convincing yet.