What is the meaning of /i
at the tail of this regex?
var time = /^([1-9]|1[0-9]):([0-5][0-9])(\s[a|p]m)$/i;
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.
$ means "Match the end of the string" (the position after the last character in the string).
The RegExp \D Metacharacter in JavaScript is used to search non digit characters i.e all the characters except digits. It is same as [^0-9]. Syntax: /\D/ or new RegExp("\\D") Syntax with modifiers: /\D/g.
/i
stands for ignore case in the given string. Usually referred to as case-insensitive as pointed out in the comment.
It's, like Sachin Shanbhag already answered the 'ignore case' modifier. So /[a-z]/i
is equal to /[a-zA-Z]/
. Check this link for other modifiers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With