2

Can anyone explain me the following piece of code

sampleQuery.replace(new RegExp("("+query+")","ig")

What is this "ig" stands for?

1 Answer 1

5

the i and the g are flags used with Regular Expressions:

g - 'global' matching - ie. gets all matches (the default behaviour is to stop after one match is found. http://www.w3schools.com/jsref/jsref_regexp_g.asp

i - makes the matches case-insensitive. http://www.w3schools.com/jsref/jsref_regexp_i.asp

hth.

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

6 Comments

Please don't refer to W3Schools: see W3Fools why. Use MDC's RegExp instead.
I'm agreeing with Marcel, W3Schools shouldn't be used as any kind of reference seeing they got outdated and terribly wrong information up there.
I don't see anything wrong with using it for quick n dirty answers such as this for novices - in my experience newbies find the interactive JS tool very useful.
I would avoid the term greedy here as it normally refers to some other behaviour in the context of regular expressions (.* vs .*?).
Ah, I see, but at least it explains what's wrong with W3Schools. And as you say: those answers become quick and dirty: those newbies will come back soon when they bluntly copy-pasted such an advice on W3Schools containing lots of security holes and illogical advice.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.