Jump to content

Some StringRegExp Patterns


Recommended Posts

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
Link to comment
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!"

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

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

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!"

Link to comment
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 ;)

Link to comment
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!"

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...