Dating on line for dummies

by  |  23-Mar-2015 10:53

Since I feel this is rather vague and non-helpful, I thought I'd make a post detailing the mechanics of the glob regex. matches 1 of any character except a / The * matches 0 or more of any character except a / If it helps, think of the * as the pcre equivalent of .* and ?

, which would match 0 or 1 of the previous character.

glob's regex also supports character classes and negative character classes, using the syntax [] and [^].

It will match any one character inside [] or match any one character that is not in [^].

With the same list above, executing glob("[ab]*.php) will return (all of them): // [ab] matches 'a', * matches nothing // [ab] matches 'a', * matches 2nd 'a' // [ab] matches 'a', * matches 'b' // [ab] matches 'a', * matches 'bc' // [ab] matches 'b', * matches nothing // [ab] matches 'b', * matches 'c' // [ab] matches 'b', * matches 'cd' glob("[ab].php") will return and glob("[^a]*.php") will return: // [^a] matches 'b', * matches nothing // [^a] matches 'b', * matches 'c' // [^a] matches 'b', * matches 'cd' glob("[^ab]*.php") will return nothing because the character class will fail to match on the first character.

You can also use ranges of characters inside the character class by having a starting and ending character with a hyphen in between.

Community Discussion