Quantcast
Channel: Capturing Groups From a Grep RegEx - Stack Overflow
Viewing all articles
Browse latest Browse all 11

Answer by chirag nayak for Capturing Groups From a Grep RegEx

$
0
0
str="1w 2d 1h"regex="([0-9])w ([0-9])d ([0-9])h"if [[ $str =~ $regex ]]then    week="${BASH_REMATCH[1]}"    day="${BASH_REMATCH[2]}"    hour="${BASH_REMATCH[3]}"    echo $week --- $day ---- $hourfi

output:1 --- 2 ---- 1


Viewing all articles
Browse latest Browse all 11

Trending Articles