ecchymose
asked on
RegExp problem with double-quote (")
I have this code:
givenPattern="&var[0-9]+=" ;
myRegExp = new RegExp(givenPattern,"i");
chunks = document.frm.textfield.val ue.split(m yRegExp);
Then I test it with 2 different texts in "textfield":
Test A)
&comment=### start ###
&var1=Hello
&var99=Cool
&comment=### end ###
Test B)
&comment=### start ###
&var1="Hello"
&var99=Cool
&comment=### end ###
---
Notice double-quotes in Test B)
Then if I alert(chunks[1]); with A) it works... Testing it with B) says chunks[1] is Undefined.
What's wrong with those double-quotes?
givenPattern="&var[0-9]+="
myRegExp = new RegExp(givenPattern,"i");
chunks = document.frm.textfield.val
Then I test it with 2 different texts in "textfield":
Test A)
&comment=### start ###
&var1=Hello
&var99=Cool
&comment=### end ###
Test B)
&comment=### start ###
&var1="Hello"
&var99=Cool
&comment=### end ###
---
Notice double-quotes in Test B)
Then if I alert(chunks[1]); with A) it works... Testing it with B) says chunks[1] is Undefined.
What's wrong with those double-quotes?
ASKER
well... problem is those texts are in fact text files... loaded in a textfield after...
But those text files content must be loaded in some Flash tool... So I don't want my variable content to print the backslashes!
But those text files content must be loaded in some Flash tool... So I don't want my variable content to print the backslashes!
Hmm
backslash escapes the quotes
like this
<script>
alert(".......\"Hello\" ......World");
</script>
Is this actionscript or what
backslash escapes the quotes
like this
<script>
alert(".......\"Hello\" ......World");
</script>
Is this actionscript or what
ASKER
yeah, but it's more complicated... example was to simplify this a LOT...
For some reasons, I don't want to change the content of the text files...
I'd prefer a solution "script-side" instead of "content-side", If I can say...
For some reasons, I don't want to change the content of the text files...
I'd prefer a solution "script-side" instead of "content-side", If I can say...
Hi,
I used the code below to test it (I use Internet Explorer 6.0) and I can't seem to get the error, can you post some more information about the other code?
Thanks,
Drackon
<HTML>
<head>
<script>
function doSplit() {
givenPattern="&var[0-9]+=" ;
myRegExp = new RegExp(givenPattern,"i");
chunks = document.frm.textfielda.va lue.split( myRegExp);
alert(chunks[1]);
chunks = document.frm.textfieldb.va lue.split( myRegExp);
alert(chunks[1]);
}
</script>
</head>
<body>
<form name=frm>
<textarea name=textfielda>
&comment=### start ###
&var1=Hello
&var99=Cool
&comment=### end ###
</textarea>
<textarea name=textfieldb>
&comment=### start ###
&var1="Hello"
&var99=Cool
&comment=### end ###
</textarea>
<BR>
<a href=# onClick="doSplit()">GO</a>
</form>
</body>
</HTML>
I used the code below to test it (I use Internet Explorer 6.0) and I can't seem to get the error, can you post some more information about the other code?
Thanks,
Drackon
<HTML>
<head>
<script>
function doSplit() {
givenPattern="&var[0-9]+="
myRegExp = new RegExp(givenPattern,"i");
chunks = document.frm.textfielda.va
alert(chunks[1]);
chunks = document.frm.textfieldb.va
alert(chunks[1]);
}
</script>
</head>
<body>
<form name=frm>
<textarea name=textfielda>
&comment=### start ###
&var1=Hello
&var99=Cool
&comment=### end ###
</textarea>
<textarea name=textfieldb>
&comment=### start ###
&var1="Hello"
&var99=Cool
&comment=### end ###
</textarea>
<BR>
<a href=# onClick="doSplit()">GO</a>
</form>
</body>
</HTML>
After you have got the textfield data you could then use this:
var txt = document.frm.textfieldb.va lue.replac e(/\"/,"\\ \"");
and then do the split. The function just replaces the " with \" after you have loaded the information
var txt = document.frm.textfieldb.va
and then do the split. The function just replaces the " with \" after you have loaded the information
The split() works as expected.
You have a typo elsewhere.
Here my test:
<html>
<head>
<script>
function showChunks(theText){
givenPattern="&var[0-9]+=" ;
myRegExp = new RegExp(givenPattern,"i");
chunks = theText.split(myRegExp);
alert(chunks);
alert(chunks[1]);
}
</script>
</head>
<body>
<form>
<textarea onClick="showChunks(this.v alue)" rows=10>
&comment=### start ###
&var1=Hello
&var99=Cool
&comment=### end ###
</textarea>
<textarea onClick="showChunks(this.v alue)" rows=10>
&comment=### start ###
&var1="Hello"
&var99=Cool
&comment=### end ###
</textarea>
</form>
</body>
</html>
You have a typo elsewhere.
Here my test:
<html>
<head>
<script>
function showChunks(theText){
givenPattern="&var[0-9]+="
myRegExp = new RegExp(givenPattern,"i");
chunks = theText.split(myRegExp);
alert(chunks);
alert(chunks[1]);
}
</script>
</head>
<body>
<form>
<textarea onClick="showChunks(this.v
&comment=### start ###
&var1=Hello
&var99=Cool
&comment=### end ###
</textarea>
<textarea onClick="showChunks(this.v
&comment=### start ###
&var1="Hello"
&var99=Cool
&comment=### end ###
</textarea>
</form>
</body>
</html>
ASKER
Well, problem is that the content is not in a textfield, but in a hidden filed, (sorry)
So I guess the error the value attribute is closed when the first " appears...
Input type="hidden" value="&comment=### start ###
&var1="Hello"
&var99=Cool
&comment=### end ###
"
As I see it, I won't have any other choice than escaping the double slashes in ALL text files...
But is there any other solution "script-side" you see?
So I guess the error the value attribute is closed when the first " appears...
Input type="hidden" value="&comment=### start ###
&var1="Hello"
&var99=Cool
&comment=### end ###
"
As I see it, I won't have any other choice than escaping the double slashes in ALL text files...
But is there any other solution "script-side" you see?
Try this:
<Input type="hidden" value='&comment=### start ###
&var1="Hello"
&var99=Cool
&comment=### end ###
' >
<Input type="hidden" value='&comment=### start ###
&var1="Hello"
&var99=Cool
&comment=### end ###
' >
ASKER
Same problem!
The single quote is sometimes used in the text...
The single quote is sometimes used in the text...
How about this:
<textarea name="textfield" style="display:none">
&comment=### start ###
&var1="Hello"
&var99=Cool
&comment=### end ###
</textarea>
<textarea name="textfield" style="display:none">
&comment=### start ###
&var1="Hello"
&var99=Cool
&comment=### end ###
</textarea>
ASKER
Oh! Nice solution!
Thanx to all, I'll take the Zvonko solution...
Thanx to all, I'll take the Zvonko solution...
ASKER
No, in fact I can't take Zvonko's solution because it's a hidden field and not a textarea...
I'll change all double-quote by a Flash readable symbol and "find and replace" after to show it...
Thanx!
I'll change all double-quote by a Flash readable symbol and "find and replace" after to show it...
Thanx!
Can you explain the difference between hidden <input> field and hidden <textarea> field?
You access the values by same syntax, so what is the problem for you?
You access the values by same syntax, so what is the problem for you?
ASKER
I think a hidden field, as it is hidden, don't have any display properties concerning CSS...
Anyway, as it was kinda urgent, I couldn't test much things, and I decided it was faster to automatically find-and-replace double quotes by some Flash readable character replacing double-quotes...
Thank you again!
Anyway, as it was kinda urgent, I couldn't test much things, and I decided it was faster to automatically find-and-replace double quotes by some Flash readable character replacing double-quotes...
Thank you again!
ASKER
Oh! Okay, I see... displat:none HIDES the Textarea...
Well, ok, it's better that way... But anyway, the tool I'm working on must be Netscape 4.x compatible... and I don't want take risks with CSS and Netscape anyway...
Well, ok, it's better that way... But anyway, the tool I'm working on must be Netscape 4.x compatible... and I don't want take risks with CSS and Netscape anyway...
You are right, I just tested NS4.7; It ignores "display:none"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ooooh! This one is really great! Ok, you got it!
<|:-)
&comment=### start ###
&var1=\"Hello\"
&var99=Cool
&comment=### end ###