Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does /i at the end of a regex mean?

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; 
like image 446
Some Java Guy Avatar asked Feb 11 '11 09:02

Some Java Guy


People also ask

What does regex 0 * 1 * 0 * 1 * Mean?

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.

What does '$' mean in regex?

$ means "Match the end of the string" (the position after the last character in the string).

What does the metacharacter \d means in regular expression?

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.


2 Answers

/i stands for ignore case in the given string. Usually referred to as case-insensitive as pointed out in the comment.

like image 63
Sachin Shanbhag Avatar answered Sep 22 '22 21:09

Sachin Shanbhag


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.

like image 26
KooiInc Avatar answered Sep 20 '22 21:09

KooiInc