I am trying to make a regex expression that will validate a number that is in the range of -100 to 100.
I made this regex expression: (^-[1-100]* |^[0-100]*) but it doesn't work as expected.
the script:
#!/bin/bash
check(){
input="test1.txt"
while read -r line; do
a=( $line )
for i in "${a[@]:1}"; do
if [[ "$i" =~ (^-[1-100]*|^[0-100]*) ]]; then
echo "$i"
fi
done
done < "$input"
}
check
the input file:
add $s0 $s1 $s3
sub $s0 $s1
addi $s1 $s2 76
lw $s2 -50($s2)
the actual result: add $s0 $s1 $s3 sub $s0 $s1 addi $s1 $s2 76 lw $s2 -50($s2)
the expected result: 76 -50($s2)