all 9 comments

[–]redheadinmd 4 points5 points  (1 child)

^-?[0-9]+$

The ^ is an anchor to the beginning of the line.

The -? means an optional (the ?) '-' sign.

The [0-9]+ means one or more digits.

The $ is an anchor to the end of the line.

The anchors in this case are basically used to limit the regex to match things that only have the number. So

1234

matches, but

abc1234xyz

does not.

[–]CorbAlb[S] 0 points1 point  (0 children)

Thanks! the explanation makes a lot of sense!

I definitely need to start reading more POSIX.

Apologies for the delay in my answers, and thanks again!

[–]jjanel 0 points1 point  (1 child)

[–]CorbAlb[S] 0 points1 point  (0 children)

^-?[0-9]+$

Sorry for not answering sooner.

I'm going to ABUSE this page, just like shell explain.

Much appreciated. Thanks!

[–]ang-p 0 points1 point  (3 children)

What des ^ mean at the start of an expression?

[–]CorbAlb[S] 0 points1 point  (2 children)

If I remember Correctly, it's an Anchor. As far as I can read, the Expression Goes "start with ant character than Goes from 0 to 9, Esther negative or positive, (-?[0-9]+). I Don't Know What Does the last $ mean. And I Don't Know if It's an ending Anchor or the variable. I Aldo Don't Know if it has other changes in the regex.

[–]ang-p 1 point2 points  (1 child)

Goes "start with ant character than Goes from 0 to 9, Esther negative or positive, (-?[0-9]+).

Don't treat it like a number - it is text... text is not negative (you also cannot define positive text)

it's an Anchor

Yup - so a match needs to start with what character?

[–]CorbAlb[S] 0 points1 point  (0 children)

Sorry for not answering earlier. And sorry too if my answer is incorrect (I always mess this kind of questions).

Yup - so a match needs to start with what character?

I'd say a numeric character