Space in REGEX in IE6

P

Paul Lautman

I was using the following code:

element.value = element.value.replace(/ /g,'');

to remove all the spaces in a string.

However in IE6 it complained with and "Expected ')'" error.

How can I tell IE6 to replace just spaces (i.e. not using \s)?

I tried /\ / and /[ ]/ but neither of them worked either.

TIA
 
G

Geoffrey Summerhayes

I was using the following code:

element.value = element.value.replace(/ /g,'');

to remove all the spaces in a string.

However in IE6 it complained with and "Expected ')'" error.

How can I tell IE6 to replace just spaces (i.e. not using \s)?

I tried /\ / and /[ ]/ but neither of them worked either.

Don't have IE6 available right now, but try /\x20/
 
L

Lee

Paul Lautman said:
I was using the following code:

element.value = element.value.replace(/ /g,'');

to remove all the spaces in a string.

However in IE6 it complained with and "Expected ')'" error.

Does it work in other browsers?
My first suspicion is that you've got a problem elsewhere in your code.

Try the following in IE6. It works for me in IE7 and Firefox:

<html>
<body>
<script type="text/javascript">
alert("Hello there, world".replace(/ /g,''));
</script>
</body>
</html>


--
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>,
I was using the following code:

element.value = element.value.replace(/ /g,'');

to remove all the spaces in a string.

However in IE6 it complained with and "Expected ')'" error.

It works in IE6 (and FF2). Perhaps your code is no more carefully
written than your article?

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 
C

Captain Paralytic

PaulLautmansaid:







Does it work in other browsers?
My first suspicion is that you've got a problem elsewhere in your code.

Try the following in IE6. It works for me in IE7 and Firefox:

<html>
<body>
<script type="text/javascript">
alert("Hello there, world".replace(/ /g,''));
</script>
</body>
</html>

--

It works in IE7 and Firefox, but fails in IE6
 
C

Captain Paralytic

Fails how?

It works in a completely clean IE6 installation (tested using Microsoft
Virtual PC and Microsoft's own IE6 XP image, copy/pasting the exact text
Lee posted).- Hide quoted text -

- Show quoted text -

I think you have misread the conversation!

I said, that I had an error and I specified that error as "Expected
')'"

Lee posted asking "Does it work in other browsers?".

I answered this question by saying that "It works in IE7 and Firefox,
but fails in IE6"

You then said "Fails how?"

I now refer you back to my first post where I said "However in IE6 it
complained with an "Expected ')'" error.", which answers you question
of "Fails how?", before you even asked it! Phew!!

Lee's suspicion was a problem elsewhere in my code. However it all
works fine in both IE7 and FF. If I replace

element.value = element.value.replace(/ /g,'');

with

element.value = element.value.replace(/\s/g,'');

then the error goes away.
 
P

Paul Lautman

Duncan said:
Perhaps, but not obviously.


No, Lee said "Try the following in IE6. It works for me in IE7 and
Firefox" and posted a minimal example. I assumed that your response
was referring to the reduced example not the original page.
Lee's question was before his code. It was directly following the quote of
my post. Thus the question referred to my original post.

However, I have now discovered what the problem actually was.

The offending code was a line in an event script for the Facile Forms
component of Mambo/Joomla. It worked fine on my machine but failed when I
sent it off to someone else and they put it on their site.

Unfortunately their site is on an intranet and so the only way I could view
it was via a VPN and then with Microsoft Remote Desktop Connection. The
browser on their server was IE6 and so I assumed that the problem was with
IE6.

However (again), Facile Forms has an option for compressing JavaScript and
HTML and this was set on their site, but not on mine.

The facile forms compress function doesn't handle regular expressions in the
scripts very well and it was stripping out the space and thus leaving the
line as:
element.value = element.value.replace(//g,'');

Thanks for all the support and ideas folks. If it hadn't been for your
assurances, I would never had bothered to look as deeply as I did.
 
P

Paul Lautman

Dr said:
In comp.lang.javascript message <[email protected]>,
| It works in IE6 (and FF2). Perhaps your code is no more carefully
| written than your article?
Ahh abuse, very helpful.
Pray tell, where precisely was my article "careless"

| It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
What??? Read the newsgroup? All of it? You have to be joking. I always
google a group before asking a question, but there is no way I could read
all of the group.
 
P

Paul Lautman

Duncan said:
"Try the following" referred to your original post and not to the code
which followed it? Interesting use of words.

Try the following was not a question. The question was "Does it work in
other browsers?"
The word "it" is a pronoun. The dictionary has this to say about it (no pun
intended):

(used to represent an inanimate thing understood, previously mentioned,
about to be mentioned, or present in the immediate context): It has
whitewall tires and red upholstery. You can't tell a book by its cover.

Note the words "previously mentioned". Thus the question referred to my
original post. My reply was to the question.

Simple really.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>,
| It works in IE6 (and FF2). Perhaps your code is no more carefully
| written than your article?
Ahh abuse, very helpful.
Pray tell, where precisely was my article "careless"

So your reading is careless too - the d key is nowhere near the y key.
| It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
What??? Read the newsgroup? All of it? You have to be joking. I always
google a group before asking a question, but there is no way I could read
all of the group.

Do you read a newspaper? probably. Do you read every word? probably
not.

With a good newsreader one can scan the Subject lines in a newsgroup
very rapidly, and one can quickly look at the articles too. I can
assess an article for probable interest in about a second and a half,
fairly reliably; quicker if it is by Randy. But you are using Outlook
Express.

You should, of course, read, heed and obey c.l.j FAQ section 2.3
sentence 1 before posting.

Knowing now what your problem was caused by : represent literal spaces
in RegExps with \x20 (the \ may need escaping) (or get the offending
software removed or corrected).
 
P

Paul Lautman

Dr said:
In comp.lang.javascript message <[email protected]>,


So your reading is careless too - the d key is nowhere near the y key.
What are you on about? I accidentaly typed "and" instead of "an".
Or perhaps you think that
"However in IE6 it complained with any"Expected ')'" error."
is good grammar!
Do you read a newspaper? probably. Do you read every word? probably
not.
And you say that I am careless in my writing!
With a good newsreader one can scan the Subject lines in a newsgroup
very rapidly, and one can quickly look at the articles too. I can
assess an article for probable interest in about a second and a half,
fairly reliably; quicker if it is by Randy. But you are using Outlook
Express.
And of course I did this, but bearing in mind the obscure cause of my
problem I did not find anything.
You should, of course, read, heed and obey c.l.j FAQ section 2.3
sentence 1 before posting.
As of course should you. The bit about quoting springs to mind.
But now I suddenly notice that the part about rudeness was of course written
with you in mind.
It's a good job that most people who frequent newsgroups are decent helpful
people. Stick around and you just might pick some of it up.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top