anthonyjr2 Posted July 10, 2017 Posted July 10, 2017 (edited) Hi guys, I am pretty bad with regex, and am having some trouble trying to come up with an expression for a certain type of string. Basically I want to be able to tell if a string is of the format: AA#####A Where the A's are any letter from A-Z and the #'s are any digit from 0-9. I've been playing around with a regex tester online for a while but I can't really seem to grasp the concept very well. Could anyone give me any tips? This isn't exactly an AutoIt specific question which is why I didn't post it in General Help & Support. Edited July 10, 2017 by anthonyjr2 UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=
iamtheky Posted July 10, 2017 Posted July 10, 2017 (edited) $str = "AB12345C" msgbox(0, '' , stringregexp($str , "[A-Z]{2}[0-9]{5}[A-Z]")) *If that is the entirety of the string you may want to put beginning/ending anchors on that pattern so that it does not match on partials. Edited July 10, 2017 by iamtheky anthonyjr2 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
jchd Posted July 10, 2017 Posted July 10, 2017 Make that stringregexp($str , "^[A-Z]{2}[0-9]{5}[A-Z]$") if you want to insure there is nothing before nor after the mandatory pattern. anthonyjr2 1 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 hereRegExp tutorial: enough to get startedPCRE 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)
iamtheky Posted July 10, 2017 Posted July 10, 2017 jinx ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
jchd Posted July 10, 2017 Posted July 10, 2017 Sorry didn't see the edit at time I hit Submit. 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 hereRegExp tutorial: enough to get startedPCRE 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)
anthonyjr2 Posted July 10, 2017 Author Posted July 10, 2017 Thanks both of you, exactly what I needed. You'd think taking a Formal Languages course would have me understanding regular expressions better, but I guess I need some more practice UHJvZmVzc2lvbmFsIENvbXB1dGVyZXI=
iamtheky Posted July 10, 2017 Posted July 10, 2017 1 minute ago, jchd said: Sorry didn't see the edit at time I hit Submit. your notification appeared on-click as though it was an additional action tied to my edit submission. I like to think I have been corrected enough that I have thoughts of hardening my patterns before you, jg, or mikell even show up ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Bowmore Posted July 10, 2017 Posted July 10, 2017 If you want to learn the syntax of regular expressions I would recommend having a look at this site. I also covers the differences between different implementations of regular expressions. http://www.regular-expressions.info/ "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
TheDcoder Posted July 10, 2017 Posted July 10, 2017 I would recommend RegexOne, it is an interactive tutorial for beginners, that is what got me started EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now