Is there a function in javascript which checks if entire string matches some regular expression
'00'.match(/^0|([1-9][0-9]*)$/g) for example returns ['0']
I know I can simply check if the matched part is equal to the string, but I'm just curious if such function already exists
edit:
'01'.match(/^0|1$/g) returns ['0', '1']
and '01'.match(/^(0|1)$/g) returns null as expected.
I though | has precedence over ^ or $. Can someone explain what /^0|1$/g actually matches?
/^0|1$/gmatches a0at the beginning of the string or a1at the end of the string.