A few of the more prominent differences (assuming unix/linux file systems):
| magic character | regex meaning | glob meaning |
|---|---|---|
| . | match any single character | match a literal period |
| ? | match zero or one occurrence of the previous character or group | match any single character |
| * | match zero or more occurrences of the previous character or group | match zero or more characters |
| + | match one or more occurrences of the previous character or group | match a literal plus-sign |
| ^ $ | anchor regex to start/end of string | match literal caret/dollar-sign |
| ( ) | capture a group of characters | not supported |
Square-bracketed character-classes (e.g. [a-z] work the same in both, but a pattern like [a-z]* will mean very different things for regex vs. glob.
It would be possible (probably easy and maybe even useful) to write a "glob-to-regex" converter, to produce a regex pattern that behaves the same as a given glob pattern, but if you're just looking up file names in a directory, you already have the glob() function to handle that, so why bother with the extra coding?
In reply to Re: Wildcard search in a directory
by graff
in thread Wildcard search in a directory
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |