Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash Why doesnt my regex work?

Tags:

regex

bash

I made this regex but it is not working.

I got this example string: ('/test/test/test/test-Test/TEST/test.sql'),

my bash code:

if [[ ${arrayQuery[$i]} =~ ([a-z0-9]+)\/([a-z0-9]+)\/([a-z0-9]+)\/([a-z0-9-]+)\/([a-z0-9]+)\/([a-z0-9]+).([a-z0-9]+) ]]; then
        queryName=$1
        echo "test $queryName"
fi

it is not priting anything can anyone explain my why this is not working?

i tried my regex on regex101.com and the regex did work on this website.

like image 301
kaspertje100 Avatar asked Feb 19 '26 18:02

kaspertje100


1 Answers

  • you need to escape the dot, otherwise it matches any character

  • your example string contains uppercase, but your regex only accepts lowercase letters

(edit: no quoting needed)

like image 104
marek.jancuska Avatar answered Feb 21 '26 07:02

marek.jancuska



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!