Sign in to follow this  
Followers 0
nAutoIT

Dont understand :class: in StringRegExpReplace

6 posts in this topic

$a = "46 te2s t+"
$b = "test"
If StringRegExpReplace($a, "[^:alpha:]", "") = StringRegExpReplace($b, "[^:alpha:]", "") Then MsgBox(1, "", StringRegExpReplace($a, "[^:alpha:]", ""))

I am trying to compare 2 strings by letters only, but i do not get it. I could not find any examples in the forums or the AutoIt Help that actually use classes.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

i am not that good with it either, but someone here helped me in the past too.

"[a-zA-Z]" that should be what you are trying.

Also http://www.rubular.com/ is an excellent site to test it.

what you are doing right now is checking if its not a letter by the way, because of the ^ in front.

Edited by cageman

Share this post


Link to post
Share on other sites

i am not that good with it either, but someone here helped me in the past too.

"[a-zA-Z]" that should be what you are trying.

Also http://www.rubular.com/ is an excellent site to test it.

That works, thanks a lot.

what you are doing right now is checking if its not a letter by the way, because of the ^ in front.

I was trying to replace all non-letters with "".

Share this post


Link to post
Share on other sites

Just to iterate on your original code...

The solution is you need to wrap those character classes...

Example:

$a = "46 te2s t+"
$b = "test"
If StringRegExpReplace($a, "[^[:alpha:]]", "") = StringRegExpReplace($b, "[^[:alpha:]]", "") Then MsgBox(1, "", StringRegExpReplace($a, "[^[:alpha:]]", ""))

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Just to iterate on your original code...

The solution is you need to wrap those character classes...

Example:

$a = "46 te2s t+"
$b = "test"
If StringRegExpReplace($a, "[^[:alpha:]]", "") = StringRegExpReplace($b, "[^[:alpha:]]", "") Then MsgBox(1, "", StringRegExpReplace($a, "[^[:alpha:]]", ""))

Dang. I tried "[[^:alpha:]]" and it did not work. Good to know what i did wrong there.

In the AutoIt Help it says:

[^:class:] Match any character not in the class, but only if the first character. [sic]

[:alpha:] letters

Is that a mistake in the AutoIt Help?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Dang. I tried "[[^:alpha:]]" and it did not work. Good to know what i did wrong there.

In the AutoIt Help it says:

[^:class:] Match any character not in the class, but only if the first character. [sic]

[:alpha:] letters

Is that a mistake in the AutoIt Help?

Yes, must be.

I always look at the entire class string ( eg. [:class:] ) as a single character.

Having said that, that would require us to wrap it in brackets ( eg. [[:class:]] ), and to prevent capture [^[:class:]].

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0