Sign in to follow this  
Followers 0
darkjohn20

Some StringRegExp Patterns

9 posts in this topic

#1 ·  Posted (edited)

Alright, so this is the first time I haven't been able to figure out a correct pattern. What I need is a pattern that will match any of the following:

r(0x90)
r(0xEEEEEEEE-0xFFFFFFFF)
r(0x11111111-0x22222222,0x98765432)

Basically I need it to match a list of hex strings, whether it be a single hex, a range, or both together.

'r\((0x[[:xdigit:]]+)\)'
works for a single hex such as the first example, but adding "-" and "," is where I've had trouble.

Also, I tried this but it only returns "0x98765432" from the third example:

r\((0x[[:xdigit:]]+-?,?)+\)

They can be in any order, and there can be an unlimited amount of them. I only need the pattern to check a single line, not a multiline control.

Could anybody help me?

Edit: Also, I need the group to be a full match of everything inside the parenthesis, so for the third example I'd like:

1
0x11111111-0x22222222,0x98765432

Where 1 would be Flag 0, and the rest would be Flag 1.

Edited by darkjohn20

Share this post


Link to post
Share on other sites



This might get you started

$sRegExp = "r\(([[:xdigit:],-0x]+)\)"

if that works for any of it then post the next problem and we can work on that.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This might get you started

$sRegExp = "r\(([[:xdigit:],-0x]+)\)"

if that works for any of it then post the next problem and we can work on that.

Everything works except that ",-" ",," "-," "--" etc. are still allowed. As far as getting the information it works.

r(0x11111111-0x22222222,0x98765432)
returns "0x11111111-0x22222222,0x98765432"

Now to fix invalid inputs in terms of symbols.

Edit: the 0 in the set can be removed because it's included in xdigit, if we continue using that set.

Edited by darkjohn20

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Can you post what you expect to be returned from each of your example lines?

This works to get each of the HEX values from any of the example lines or all of them together using the global match flag (3). It skips the 3 characters in the first group which are (-,

$sRegExp = "[^\(,-]*(0x[[:xdigit:]]+)"

EDIT:

I would use the global match regardless and loop through them with 0 To Ubound($array) -1 Even if there is only a single match as in your first line it will still work fine.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

I'm actually just going to go with your previous pattern. It works well enough for me to know what I'm doing. If I distribute my script in the future I might update the pattern to check for errors, but for now I'll just watch what I'm doing.

Thanks ;)

Share this post


Link to post
Share on other sites

No problem. Did you try the second pattern?


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I didn't, but I will now.

With the new line:

pattern = [^\(,-]*(0x[[:xdigit:]]+)
test = r(0x11111111-0x22222222,0x98765432)
returns 0x11111111
Edited by darkjohn20

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

(?:r\x28|\x2d|\x2c|)(0x[0-F]+)(?:\x29|\x2c|\x2d)

Done.

Edited by 4ggr35510n

Share this post


Link to post
Share on other sites

(?:r\x28|\x2d|\x2c|)(0x[0-F]+)(?:\x29|\x2c|\x2d)

Done.

Same thing.

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