Sign in to follow this  
Followers 0
Valiante

StringRegExp Syntax

17 posts in this topic

Sticking to the examples in the Help file, why does this work...

$asResult = StringRegExp("You deflect 36 of Gnarly Monster's 279 damage.", '([0-9]{1,3})(?: damage)', 1)
If @error == 0 Then
    MsgBox(0, "SRE Example 6 Result", $asResult[0])
EndIf

And this doesn't...

$asResult = StringRegExp("You deflect 36 of Gnarly Monster's 279 damage.", '([:digit:]{1,3})(?: damage)', 1)
If @error == 0 Then
    MsgBox(0, "SRE Example 6 Result", $asResult[0])
EndIf

With the only difference being [0-9] changing to [:digit:].

(Before you ask me why I don't just use [0-9], it's because I want to use the [:alnum:] class in my own script but can't get it to work, so by doing the above I'm trying to prove the the alternative [: ... :] classes work, however they don't seem to.)

Share this post


Link to post
Share on other sites



I wish I knew, but I've always had no luck with character classes in AutoIt :-/ Instead of using a class you can just use \w as long as you know there won't be any underscores.


Regards,Josh

Share this post


Link to post
Share on other sites

Because the name of the class is [:digit:] but you still must enclose it in []. So the pattern should be:

'([[:digit:]]{1,3}) damage'
I also removed your non-capturing group as it was pointless.

Share this post


Link to post
Share on other sites

Haha, that makes things so much better! Why did I never know that :P That should be in the help file :P


Regards,Josh

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Oh you're the man - \w has worked. Thanks a million!

*EDIT: Oh, lots of replies since I refreshed! :-P

That's ridiculous about enclosing brackets in brackets, but it works. Thanks guys!

Edited by Valiante

Share this post


Link to post
Share on other sites

I also removed your non-capturing group as it was pointless.

Not if you just want it to return a numerical value! It's like that in the help file already, so technically it's not "my" pointless non-capturing group! :-p

Share this post


Link to post
Share on other sites

Not if you just want it to return a numerical value!

This statement makes no sense. The only capturing group specified is for the numeric class. It's not going to capture the text. Period. There are uses for non-capturing groups, usually when you need to group things but not capture them. But you didn't group anything, you just had a literal string which does not require the non-capturing group.

It's like that in the help file already, so technically it's not "my" pointless non-capturing group! :-p

Where?

Share this post


Link to post
Share on other sites
ression">

Let's say your log says "You deflect 36 of Gnarly Monster's 279 damage." Now if you run Example 5's SRE on this, you'll come up with "36" instead of "279". Now what I like to do here is just determine what's different between the numbers. One that jumps out at me is that the second number is always followed by a space and then the word "damage". We could just modify our previous pattern to be "([0-9]{1,3} damage)", but what if our script is just looking for the amount of damage, without " damage" tacked onto the end of the number? Here's where you can use a non-capturing group to accomplish this.

Share this post


Link to post
Share on other sites

I fucking hate you people. I'm going to start punching you people in the face if you don't start posting *mother fucking paths* to stuff in the documentation. Just giving me some random text doesn't help me (much). In case you guys haven't noticed, the documentation is large. Just because you know where something is doesn't mean we do.

I'm seriously tired of this, too. Bitching aside, you guys do need to give more information. For example, I didn't even know that tutorial page existed. Tell us the index name of something or tell us the URL or tell us the correct headings to go through on the contents page.

At any rate, I did manage to find the page with the search feature. All I have to say is... way to take things out of context! That example is teaching how to use non-capturing groups. It's contrived to demonstrate a point. So here's where you're at fault, OP. You contrived an example sourcing it from a contrived example. Bad. Don't include extraneous crap in your examples. People like me will see it and wonder why it's there. It always feels like I'm doing half the diagnostic work for you when I have to weed through all the unnecessary crap or figure out the crap you didn't provide. Very frustrating.

Share this post


Link to post
Share on other sites

"AutoIt Help file - String Regular expression" wasn't enough information for you?

Wow you really have lost it man. Take a break!

Share this post


Link to post
Share on other sites

"AutoIt Help file - String Regular expression" wasn't enough information for you?

Ahh, you put some vague information in the "quote from" area. Honestly, had I seen that, no it wouldn't have been helpful. Why? Because to find it requires looking through a sub-item. And given that there are 8 sub-items, many of which have more sub-items... you get the point? Full path.

Wow you really have lost it man. Take a break!

You assume I had it from the beginning.

Share this post


Link to post
Share on other sites

Ahh, you put some vague information in the "quote from" area. Honestly, had I seen that, no it wouldn't have been helpful. Why? Because to find it requires looking through a sub-item. And given that there are 8 sub-items, many of which have more sub-items... you get the point? Full path.

Ahh, you're using the "Contents" tab to find articles. Such hard work! See, I find it much easier to use the "Index" tab. No sooner would you have typed "str" you would have seen the aforementioned article but only second in the list!

You assume I had it from the beginning.

Yes, one would hope that people offering help, albeit with a slightly condescending tone, actually have full possession of all their marbles. It usually helps.

Share this post


Link to post
Share on other sites

Ahh, you're using the "Contents" tab to find articles. Such hard work! See, I find it much easier to use the "Index" tab. No sooner would you have typed "str" you would have seen the aforementioned article but only second in the list!'

First, as I said, I didn't even see your text mentioning the title. Second, what does it matter how I normally use to find things (which is by index)? YOU were the one pointing something out to me but you couldn't be arsed to actually give me a set of reproduceable steps to find it. That is my point. If you want me to find something... tell me how to find it. Otherwise, expect large quantities of bitching. If you can't make my life easy, don't expect me to make yours easy.

Share this post


Link to post
Share on other sites

If you can't make my life easy, don't expect me to make yours easy.

I don't need you to make my life easy, I seem to manage just fine by treating people the way I like to be treated, not the exact opposite by making unnecessary comments.

Share this post


Link to post
Share on other sites

I don't need you to make my life easy, I seem to manage just fine by treating people the way I like to be treated, not the exact opposite by making unnecessary comments.

Predictable irony. I guess that makes you a hypocrite. Enjoy thinking about that for the next 24 hours while you are banned.

Share this post


Link to post
Share on other sites

It's such a shame that of all the friendly helpful guys on here it takes one disgruntled admin who has no other way of ending a conversation than by suspending a user who hasn't even come close to being insulting, when the admin can't even get his own point across without resorting to profanity and eventually forcefully preventing said user from even replying. How sad.

Don't bother suspending or deleting this or my other account, I have disabled email notifications and won't be coming back anytime soon.

Share this post


Link to post
Share on other sites

That's fine because what you have just done is an offense that garners a permanent ban. Which, as usual, the fact that you would sink to such behavior shows you aren't a user worth having around anyway.

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