Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Javascript / Client Side Development

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

On May 9, 4:01 pm, "Paul Lautman" <paul.laut@btinternet.com> wrote:

> 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

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>

--

On 9 May, 23:00, Lee <REM0VElbspamt@cox.net> wrote:

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

On 10 May, 15:06, Duncan Booth <duncan.bo@invalid.invalid> wrote:

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.

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.
In comp.lang.javascript message <5aenl7F2mjf0@mid.individual.net>,
Wed, 9 May 2007 21:01:44, Paul Lautman <paul.laut@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.htm> jscr maths, dates, sources.
 <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

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.

Dr J R Stockton wrote:
> In comp.lang.javascript message <5aenl7F2mjf0@mid.individual.net>,
> Wed, 9 May 2007 21:01:44, Paul Lautman <paul.laut@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.

"Paul Lautman" <paul.laut@btinternet.com> wrote:
> 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.

Duncan Booth wrote:
> "Paul Lautman" <paul.laut@btinternet.com> wrote:

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

In comp.lang.javascript message <5ah5rtF2mk4q@mid.individual.net>,
Thu, 10 May 2007 19:16:30, Paul Lautman <paul.laut@btinternet.com>
posted:

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.html> ff. with care.

Dr J R Stockton wrote:

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.
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc