Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash regular expression different formats

Tags:

regex

linux

bash

I have used regular expression in my code like this: .*[^0-9].*

But recently I have seen some functions implemented like this: *[!0-9]* for the same purpose of first example, that is non-integer numbers.

So I confused what is the true form of regex and what is the difference of them.

can anybody help me in this issue?

like image 240
muradin Avatar asked Dec 02 '25 04:12

muradin


1 Answers

There is only one regular expression - the first one. The second one is a glob pattern.

See regex(7) for the description of POSIX extended regular expressions supported by Bash: http://man7.org/linux/man-pages/man7/regex.7.html

See Bash manual for the description of glob patterns: http://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html

Bash uses regular expressions in [[…]] command only: http://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html

Bash uses glob patterns for everything else.

like image 60
spbnick Avatar answered Dec 03 '25 18:12

spbnick