51

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; 
4
  • 5
    Note that [a|p] matches a, | or p (yes, the | as well!). Inside a character set, the pipe has no special meaning. So you'll probably want to do: [ap]m which matches am or pm. Commented Feb 11, 2011 at 9:33
  • 1
    Also, you first part ([1-9]|1[0-9]) will only match '1', '2', '3', ... , '19'. Is that correct? Commented Feb 11, 2011 at 9:41
  • @Bart: Thanks. Now if I want digits-digits i.e xxxx-xx i.e n digits n then - and then one or two digits, my regex will look like this? /^\d+-\d{1,2}$/ or something else? Commented Feb 11, 2011 at 9:57
  • @Bart: I need your input here (stackoverflow.com/questions/4966520/…) Commented Feb 11, 2011 at 10:47

2 Answers 2

89

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

Sign up to request clarification or add additional context in comments.

3 Comments

usually referred to as case-insensitive
@oneofthelions: Full syntax is readily available in the spec: ecma-international.org/publications/standards/Ecma-262.htm And there might be the odd website or two providing JavaScript regular expressions info in more accessible language.
@Piskvor - yes, thanks. I totally forgot that word and had type incase-sensitive..:) Have edited my answer for this.
9

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.