Jump to content

Dont understand :class: in StringRegExpReplace


Recommended Posts

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
Link to comment
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 "".
Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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?

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...