Clean up XML string

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Clean up XML string

Lee Sylvester

Hey guys,

 

I’m trying to clean up XML strings in haXe by removing all illegal characters before parsing (otherwise, I get errors).  Now, I’m attempting to use regex.  I have a formula I believe will work, in the form

 

var r = ~/[^\u0021-\u002f\u003a-\u0040\u005b-\u005e\u0060\u007b-\u007e]/g;

content = r.replace( content, "" );

 

Problem is, haXe doesn’t like Unicode formats in regex… Does anyone have a solution or know how I can convert this Unicode regex into a haXe friendly regex?

 

Thanks,

Lee


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Clean up XML string

jamesbjackson
<base href="x-msg://222/">Yeap

If you can pass a string to a regular expression in HaXe like this.. 
var regEx : EReg = new EReg("/[^\u0021-\u002f\u003a-\u0040\u005b-\u005e\u0060\u007b-\u007e]/g", "");

But I get a compiler error saying "Invaild Escape Character" :-(

James


On 29 Jul 2011, at 15:58, Lee Sylvester wrote:

Hey guys,
 
I’m trying to clean up XML strings in haXe by removing all illegal characters before parsing (otherwise, I get errors).  Now, I’m attempting to use regex.  I have a formula I believe will work, in the form
 
var r = ~/[^\u0021-\u002f\u003a-\u0040\u005b-\u005e\u0060\u007b-\u007e]/g;
content = r.replace( content, "" );
 
Problem is, haXe doesn’t like Unicode formats in regex… Does anyone have a solution or know how I can convert this Unicode regex into a haXe friendly regex?
 
Thanks,
Lee
-- 
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Clean up XML string

Nicolas Cannasse
Le 29/07/2011 17:19, James Jackson a écrit :
> Yeap
>
> If you can pass a string to a regular expression in HaXe like this..
> varregEx : EReg =
> newEReg("/[^\u0021-\u002f\u003a-\u0040\u005b-\u005e\u0060\u007b-\u007e]/g",
> "");
>
> But I get a compiler error saying "Invaild Escape Character" :-(

You need to escape your backslashes :

new
EReg("[^\\u0021-\\u002f\\u003a-\\u0040\\u005b-\\u005e\\u0060\\u007b-\\u007e]","g");

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Clean up XML string

jamesbjackson
Thanks Nicolas! :-)

James


On 29 Jul 2011, at 16:27, Nicolas Cannasse wrote:

> Le 29/07/2011 17:19, James Jackson a écrit :
>> Yeap
>>
>> If you can pass a string to a regular expression in HaXe like this..
>> varregEx : EReg =
>> newEReg("/[^\u0021-\u002f\u003a-\u0040\u005b-\u005e\u0060\u007b-\u007e]/g",
>> "");
>>
>> But I get a compiler error saying "Invaild Escape Character" :-(
>
> You need to escape your backslashes :
>
> new EReg("[^\\u0021-\\u002f\\u003a-\\u0040\\u005b-\\u005e\\u0060\\u007b-\\u007e]","g");
>
> Nicolas
>
> --
> haXe - an open source web programming language
> http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

RE: Clean up XML string

Lee Sylvester
In reply to this post by Nicolas Cannasse
Awesome.  Thanks Nicolas (and thanks, too, James).  I figured I must be
doing something wrong ;-)

Lee


-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nicolas Cannasse
Sent: 29 July 2011 16:28
To: The haXe compiler list
Subject: Re: [haXe] Clean up XML string

Le 29/07/2011 17:19, James Jackson a écrit :
> Yeap
>
> If you can pass a string to a regular expression in HaXe like this..
> varregEx : EReg =
> newEReg("/[^\u0021-\u002f\u003a-\u0040\u005b-\u005e\u0060\u007b-\u007e
> ]/g",
> "");
>
> But I get a compiler error saying "Invaild Escape Character" :-(

You need to escape your backslashes :

new
EReg("[^\\u0021-\\u002f\\u003a-\\u0040\\u005b-\\u005e\\u0060\\u007b-\\u007e]
","g");

Nicolas

--
haXe - an open source web programming language http://haxe.org


--
haXe - an open source web programming language
http://haxe.org