Jump to content

StringRegExp - numbers w/o letters in pattern


Recommended Posts

Hello,

I have spent the past day fooling with StringRegExp to no avail attempting to get what would be a simple solution to an issue using StringRegExp.

I will post the code in a sec. The string 'Java x Update y' where x and y are numeric values ONLY if a letter is mixed in anywhere then it should fail. I have been able to successfully deal with the x value so if x = 1234 or a1234 or 1a234 or 1234a would result in a fail if 'a' was in the string. However, when y = 1a234 then I get an output of 1 and when y = 1234a then the output = 1234 when both should fail. I am probably overlooking something simple and in looking through all the material and experimenting I am unable to figure it out and my experience with stringregexp and trying to find examples of this proved difficult. If someone could assist or point me to a thread ? Here is my code ; prob a simple fix. I am also trying to avoid white spaces.

Thanks in advance

#include <array.au3>

$aArray = StringRegExp('Java 3009 Update 1a21', '(?i)Java (\d+) Update (\d+)', $STR_REGEXPARRAYGLOBALMATCH)
If @error Then Exit
_ArrayDisplay($aArray)

 

Link to comment
Share on other sites

By using \b to request word boundary before and after \d+ you can get what I believe you're after.

#include <array.au3>

$aArray = StringRegExp('Java 3009 Update 1a21', '(?i)Java (\b\d+\b) Update (\b\d+\b)', $STR_REGEXPARRAYGLOBALMATCH)
_ArrayDisplay($aArray)

$aArray = StringRegExp('Java 3z09 Update 1a21', '(?i)Java (\b\d+\b) Update (\b\d+\b)', $STR_REGEXPARRAYGLOBALMATCH)
_ArrayDisplay($aArray)

$aArray = StringRegExp('Java 3009 Update 1521', '(?i)Java (\b\d+\b) Update (\b\d+\b)', $STR_REGEXPARRAYGLOBALMATCH)
_ArrayDisplay($aArray)

Note nevertheless that \b relies on the PCRE definition of "word characters", i.e. [0-9A-Za-z_] where the underscore IS a word letter.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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

×
×
  • Create New...