How come my regex isn't working as expected in Bash? Greedy instead of Lazy
问题 How come my regex pattern isn't lazy? It should be capturing the first number, not the second. Here is a working bash script.. #!/bin/bash text='here is some example text I want to match word1 and this number 3.01 GiB here is some extra text and another number 1.89 GiB' regex='(word1|word2).*?number[[:blank:]]([0-9.]+) GiB' if [[ "$text" =~ $regex ]]; then echo 'FULL MATCH: '"${BASH_REMATCH[0]}" echo 'NUMBER CAPTURE: '"${BASH_REMATCH[2]}" fi Here is the output... FULL MATCH: word1 and this