469,329 Members | 1,460 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,329 developers. It's quick & easy.

Space in REGEX in IE6

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
May 9 '07 #1
13 1873
On May 9, 4:01 pm, "Paul Lautman" <paul.laut...@btinternet.comwrote:
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/

----
Geoff

May 9 '07 #2
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>
--

May 9 '07 #3
On 9 May, 23:00, Lee <REM0VElbspamt...@cox.netwrote:
PaulLautmansaid:
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>

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

May 10 '07 #4
Captain Paralytic <pa**********@yahoo.comwrote:
On 9 May, 23:00, Lee <REM0VElbspamt...@cox.netwrote:
>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
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).
May 10 '07 #5
On 10 May, 15:06, Duncan Booth <duncan.bo...@invalid.invalidwrote:
Captain Paralytic <paul_laut...@yahoo.comwrote:
On 9 May, 23:00, Lee <REM0VElbspamt...@cox.netwrote:
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

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.

May 10 '07 #6
Captain Paralytic <pa**********@yahoo.comwrote:
On 10 May, 15:06, Duncan Booth <duncan.bo...@invalid.invalidwrote:
>Captain Paralytic <paul_laut...@yahoo.comwrote:
On 9 May, 23:00, Lee <REM0VElbspamt...@cox.netwrote:
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

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!
Perhaps, but not obviously.
>
I said, that I had an error and I specified that error as "Expected
')'"

Lee posted asking "Does it work in other browsers?".
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.
>
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!!
I understood that your original code fails with "Expected ')'", but I
wanted to know how Lee's reduced example fails for you in IE6.
>
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.
Great, but to the best of my knowledge IE6 has no problems with the first
form either.
May 10 '07 #7
In comp.lang.javascript message <5a*************@mid.individual.net>,
Wed, 9 May 2007 21:01:44, Paul Lautman <pa**********@btinternet.com>
posted:
>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) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
May 10 '07 #8
Duncan Booth wrote:
Captain Paralytic <pa**********@yahoo.comwrote:
>On 10 May, 15:06, Duncan Booth <duncan.bo...@invalid.invalidwrote:
>>Captain Paralytic <paul_laut...@yahoo.comwrote:
On 9 May, 23:00, Lee <REM0VElbspamt...@cox.netwrote:
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

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!

Perhaps, but not obviously.
>>
I said, that I had an error and I specified that error as "Expected
')'"

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

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.
May 10 '07 #9
Dr J R Stockton wrote:
In comp.lang.javascript message <5a*************@mid.individual.net>,
Wed, 9 May 2007 21:01:44, Paul Lautman <pa**********@btinternet.com>
posted:
>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?
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.

May 10 '07 #10
"Paul Lautman" <pa**********@btinternet.comwrote:
Lee's question was before his code. It was directly following the
quote of my post. Thus the question referred to my original post.
"Try the following" referred to your original post and not to the code
which followed it? Interesting use of words.
May 10 '07 #11
Duncan Booth wrote:
"Paul Lautman" <pa**********@btinternet.comwrote:
>Lee's question was before his code. It was directly following the
quote of my post. Thus the question referred to my original post.

"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.

May 10 '07 #12
In comp.lang.javascript message <5a*************@mid.individual.net>,
Thu, 10 May 2007 19:16:30, Paul Lautman <pa**********@btinternet.com>
posted:
>Dr J R Stockton wrote:
>In comp.lang.javascript message <5a*************@mid.individual.net>,
Wed, 9 May 2007 21:01:44, Paul Lautman <pa**********@btinternet.com>
posted:
>>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?
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).

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
For news:borland.*, use their server newsgroups.borland.com ; but first read
Guidelines <URL:http://www.borland.com/newsgroups/guide.htmlff. with care.
May 11 '07 #13
Dr J R Stockton wrote:
In comp.lang.javascript message <5a*************@mid.individual.net>,
Thu, 10 May 2007 19:16:30, Paul Lautman <pa**********@btinternet.com>
posted:
>Dr J R Stockton wrote:
>>In comp.lang.javascript message
<5a*************@mid.individual.net>, Wed, 9 May 2007 21:01:44,
Paul Lautman <pa**********@btinternet.composted:
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?
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.
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!
>
>>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.
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.

May 12 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Xah Lee | last post: by
16 posts views Thread by simonc | last post: by
1 post views Thread by Guoqi Zheng | last post: by
5 posts views Thread by Johny | last post: by
8 posts views Thread by =?Utf-8?B?TTFpUw==?= | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.