I'm trying to match some lines against regex that contains digits.
Bash version 3.2.25:
#!/bin/bash
s="AAA (bbb 123) CCC"
regex="AAA (bbb d+) CCC"
if [[ $s =~ $regex ]]; then
echo $s matches $regex
else
echo $s doesnt match $regex
fi
Result:
AAA (bbb 123) CCC doesnt match AAA (bbb d+) CCC
If I put regex="AAA (bbb .+) CCC"
it works but it doesn't meet my requirement to match digits only.
Why doesn't d+
match 123
?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…