0

I have no idea what is happening here..

model.attributes.data.Path.replace('/\\/g',""), @options.path.replace('/\\/g',"")

When doing :

console.log model.attributes.data.Path.replace('/\\/g',""), 
@options.path.replace('/\\/g',"")

the data is:

T2/T2_2, T2/T2_2

It returns this:

T2T2_2, T2/T2_2

So only the first path was replaced, but not the second one? Why would that be?

5
  • What was the input data? Commented Jan 23, 2013 at 14:06
  • it was T2/T2_2 , T2/T2_2 Commented Jan 23, 2013 at 14:06
  • Sory, changed it, needs to be , not == Commented Jan 23, 2013 at 14:08
  • no, thats not what I am doing. Im doing two replaces, its not one string. Im just logging them next to each other Commented Jan 23, 2013 at 14:10
  • 114 questions and did not learn how to format your code in your questions? Commented Jan 23, 2013 at 14:10

3 Answers 3

2

Aside from the fact you're matching backslashes (\\ = \), instead of forward slashes (\/ = /), Don't put your regexes into the replace function as strings.

Use:

.replace(/\//g,"");

Instead of

.replace('/\//g',"");

Then it'll work just fine:

"T2/T2_2 , T2/T2_2".replace(/\//g,"");
// returns: "T2T2_2 , T2T2_2"

Otherwise, it'll just try to literally find the string '/\//g'.

Also, to replace both forward and backslashes in 1 regex, try this:

"T2/T2_2 , T2\T2_2".replace(/\/|\\/g,"");
// returns: "T2T2_2 , T2T2_2"

# \/|\\ Matches:
# \/  - Forward slash
# |   - Or
# \\  - Backslash
Sign up to request clarification or add additional context in comments.

Comments

1

Try .replace(/\//g,"") instead of .replace('/\\/g',""), (the regex is not a string).

Comments

1

Try:

model.attributes.data.Path.replace(/\//g,"")
@options.path.replace(/\//g,"")

/\\/g matches a backslash and /\//g matches a forward slash.

2 Comments

That is actually the problem, I missed it and neglected to write it in the question. The first one contains a backslash and the second a forward. it was actually T2\T2_2 , T2/T2_2
@Harry, noticed, but only part of the problem :P

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.