javascript - Local modifiers in JS -



javascript - Local modifiers in JS -

somehow

var regex=/a(?i)b/;

lets js console in firefox tell me "invalid quantifier". know what's wrong it?

update:

i saw @ http://regex101.com/r/iw3ke7 (?i) seems not work in js (but in php). how do such things local modifiers in js?

i'm trying introduce case insensitivity (?i).

answer updated question:

i'm trying introduce case insensitivity (?i).

you can't in javascript, look whole either case-sensitive, or not. case-insensitive look using i flag @ end:

var rex = /expression/i;

so if goal match a (in lower case) followed b or b, look be:

var rex = /a[bb]/;

i'm sure actual utilize case isn't simple , going complicate things real expression, unfortunately there isn't way start out beingness case-sensitive , switch beingness case-insensitive part-way through. either have character class thing (above), or split multiple expressions , create sure matches first 1 followed matches sec one. in fact, create utility function/object accepts series of regular expressions, , looks matches expressions adjacent each other, e.g.:

var matcher = new myniftymatcherthing(/a/, /b/i); if (matcher.exec(somestring)) { // ... }

answer before clarification of question:

the ? (a quantifier meaning "zero or one") has refer in front end of it, there's nil in front end of in capture grouping refer to.

you haven't said you're doing, if goal either have or not have i between a , b, , capture if it's there, have characters reversed:

var regex=/a(i?)b/;

if goal create i optional without capturing it, you'd combine quantifier non-capturing grouping (so applies i, not a):

var regex=/a(?:i?)b/;

if goal have non-capturing grouping (although i'm not quite sure why you'd need 1 letter i), need : after ?:

var regex=/a(?:i)b/;

(or there's (?=...) positive lookahead, or (?!...) negative lookahead.)

javascript regex

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -