Skip to content Skip to sidebar Skip to footer

What Does The D Flag Mean In A Javascript Regex?

I have a regex, that appears to work in Safari and Chrome that gives the following error in FireFox. Error: invalid regular expression flag d Source File: http://java.net/projects/

Solution 1:

There is no d flag, which is your issue :) There are:

  • g - Global search (multiple matches)
  • i - Case insensitive
  • m - Multiple input

Solution 2:

Webkit browsers are more tolerant in this case, and will accept something like this:

/theregex/zxcvbgi

Instead of throwing am error, they see it as:

/theregex/gi

Firefox, however, will object to any invalid flags. Nick points out the valid ones in his answer.

Solution 3:

Are you sure it actually does something in Chrome? I tried:

/projects\/[^/]+/zyx

It accepts that as /projects\/[^/]+/, but I strongly doubt those are all real extensions. It's just ignoring them. as noted by Ken, it will keep valid flags even if invalid ones are present.

Also, I recommend you follow a good tutorial, rather than just cutting and pasting.

Post a Comment for "What Does The D Flag Mean In A Javascript Regex?"