Check octal number
1 answer
You can use the following regex to match octal numbers only:
^0[1-7][0-7]*$
-
^,$
: Anchors -
0
: Literal0
. Start all octal numbers with0
. -
[1-7]
: Char class for digits 1 through 7, since only they are valid octal digits. -
*
: Quantifier for zero or more.
So basically, this regex will only match lines that start 0
at the beginning and contain one or more digits from 1
to 7
.
If there is 0
no leading requirement , you can use a regular expression:
^[1-7][0-7]*$
+3
a source to share