6

I am using the following code to convert a dynamic string into a valid class.

domain.replace('.','_','gi')

This works fine in all major browsers, but not in Internet Explorer and I'm wondering why. The gi flags are for global and case insensitive, but removing them means that the replace doesn't work in Firefox either.

Any ideas on how I change this to make it more friendly with more browers?

1
  • 1
    What happens or doesn't happen? What is the expected and actual result? Commented Dec 6, 2010 at 17:59

2 Answers 2

10

You'll need to use an actual regexp instead of a string:

domain.replace(/\./g, "_")

The third argument (flags) is non-standard.

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

3 Comments

@elusive: Why would you need the i flag for a dot?
Good point. I recognized it a few seconds after i submitted. Sorry about that. +1 for the non-standard hint ;)
Cracking! That's what I was missing. Will accept in 6 minutes :)
7

You need to do it like this:

domain.replace(/\./g, '_');

Comments

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.