I could be wrong, but after a quick read from here , especially in note 2 at the end of the page, bash can sometimes include a newline when matching with a dot operator. Therefore, a quick solution would be the following:
#!/bin/bash str='foo = 1 bar = 2 boo = 3 ' re='bar = ([^\ ]*)' if [[ "$str" =~ $re ]]; then echo "${BASH_REMATCH[1]}" else echo no match fi
Note that I am now asking that this matches anything other than newlines. Hope this helps =)
Edit: Also, if I understood correctly, then ^ or $ actually correspond to the beginning or end (respectively) of the line, not the line. It would be better if someone else could confirm this, but it is, and you want to combine the lines, you need to write a while loop for each line separately.
Janito Vaqueiro Ferreira Filho
source share