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

2

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;
Tonguing answered 11/2, 2011 at 9:23 Comment(4)
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.Hypnos
Also, you first part ([1-9]|1[0-9]) will only match '1', '2', '3', ... , '19'. Is that correct?Hypnos
@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?Tonguing
@Bart: I need your input here (#4967020)Tonguing
G
87

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

Geniegenii answered 11/2, 2011 at 9:24 Comment(3)
usually referred to as case-insensitiveRetroflex
@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.Estragon
@Piskvor - yes, thanks. I totally forgot that word and had type incase-sensitive..:) Have edited my answer for this.Geniegenii
A
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.

Albina answered 11/2, 2011 at 9:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.