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.

I am looking for a number pattern in a string, not just a number by itself.

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).

`[0-100]`

will not be parsed as a range from 0 to 100 like you expect, but as 3 items:`0-1`

,`0`

,`0`

.`0-1`

will indeed be the range from`0`

to`1`

, so all added`[0-100]`

is the same as`[0100]`

which is just`[01]`

or`(0|1)`

.`[1-100]`

will in fact be the exact same thing.`[..]`

is for character classes so things in it are understood character by character. Also the`*`

applies to the token before it and means the token can appear never or once or multiple times (unbounded), so your [0-100]* means in fact: empty string, or unlimited amounts of`0`

or`1`

. – Patrick Mevzek Mar 29 at 19:23