syno Posted March 24, 2009 Share Posted March 24, 2009 Hi guys I know this is probably quiet straight forward but I need to match specific figures. The code below matches 1 a minimum of 4 times. However I need a minimum of 4 and maximum of 4. MsgBox(0, "SRE Example 3 Result", StringRegExp('1111', '1{4}') Any help would be appreciated... Thanks Link to comment Share on other sites More sharing options...
Marc Posted March 24, 2009 Share Posted March 24, 2009 According to the helpfile: {x, y} Repeat the previous character, set or group between x and y times, inclusive So I'd suggest simply using MsgBox(0, "SRE Example 3 Result", StringRegExp('1111', '1{4,4}')) Hope this helps, Marc Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
rudi Posted March 24, 2009 Share Posted March 24, 2009 Hi guys I know this is probably quiet straight forward but I need to match specific figures. The code below matches 1 a minimum of 4 times. However I need a minimum of 4 and maximum of 4. MsgBox(0, "SRE Example 3 Result", StringRegExp('1111', '1{4}') I think you want to match "ABC1111DEF", but not "ABC111DEF" as well as not "ABC11111DEF", right? Try this one: (?:[^1]{1})(1{4})(?:[^1]{1}) Step by step: (?:[^1]{1}) "(?:" opens a non capturing group [^1] a group matching any CHAR except "1" {1} one "non 1" will do. (1{4}) "1" literally, exactly 4 times. and finally again exactly one "non 1" CHAR. Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Ascend4nt Posted March 24, 2009 Share Posted March 24, 2009 (edited) Rudi's code is good, but if the 4 1's falls at the beginning or end of a string, you'll need to add two 'OR' statements. Plus, unless you are capturing the data, you don't need the ?:, and the {1} isn't necessary since 1 instance is always implied. Here's an example that matches anywhere in a string. Note that if you have a multi-line string, you'll need to make further adjustments (like adding (?m) at the start). Here's a modified version of Rudi's: (^|[^1])1{4}([^1]|$) *edit: also, the () around '1{4}' wasn't necessary (unless again you are capturing groups) Edited March 24, 2009 by ascendant My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
syno Posted March 26, 2009 Author Share Posted March 26, 2009 Hi guys I have tried both: (^|[^1])1{4}([^1]|$) and (?:[^1]{1})(1{4})(?:[^1]{1}) but I get the following error message: Unable to parse line.: MsgBox(0, "SRE Example 3 Result", StringRegExp('111111', (^|[^1])'1{4}'([^1]|$))) MsgBox(0, "SRE Example 3 Result", StringRegExp('111111', (^^ ERROR Link to comment Share on other sites More sharing options...
GEOSoft Posted March 26, 2009 Share Posted March 26, 2009 (edited) The RegExp has to be quoted MsgBox(0, "SRE Example 3 Result", StringRegExp('111111', "(^|[^1])'1{4}'([^1]|$)")) Edited March 26, 2009 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 More sharing options...
Ascend4nt Posted March 26, 2009 Share Posted March 26, 2009 (edited) Unable to parse line.: MsgBox(0, "SRE Example 3 Result", StringRegExp('111111', (^|[^1])'1{4}'([^1]|$))) MsgBox(0, "SRE Example 3 Result", StringRegExp('111111', (^^ ERROR Uh, why did you put a ' in there twice? And GEOSoft is correct, the string must be quoted. So use: StringRegExp("111111","(^|[^1])1{4}([^1]|$)") ; For FALSE StringRegExp("1111","(^|[^1])1{4}([^1]|$)") ; For TRUE *edit: oops, put a "", in there by mistake Edited March 26, 2009 by ascendant My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
syno Posted March 26, 2009 Author Share Posted March 26, 2009 (edited) Fantastic, that worked. I just needed the '' or "" outside the brackets so: MsgBox(0, "SRE Example 3 Result", StringRegExp('1111','(^|[^1])1{4}([^1]|$)')) ; TRUE Thanks for all your help people..! Edited March 26, 2009 by syno Link to comment Share on other sites More sharing options...
syno Posted March 31, 2009 Author Share Posted March 31, 2009 Hi guys What if I wanted to match non digits such as the following: : , / x - Link to comment Share on other sites More sharing options...
GEOSoft Posted March 31, 2009 Share Posted March 31, 2009 [:|,|/|x|-] to match the list you gave. or you could use the [:punct:] class to match any punctuation. 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 More sharing options...
syno Posted March 31, 2009 Author Share Posted March 31, 2009 [:|,|/|x|-] to match the list you gave. or you could use the [:punct:] class to match any punctuation. I have tried: StringRegExp('100,000','(^|[,][^1][^0])1{1}0{5},{1}([^1][^0][,]|$)' and it returns false. What am I doing wrong? Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 31, 2009 Share Posted March 31, 2009 Hi, can you give some examples like this String ..... = you need ... String ..... = you need ... String ..... = you need ... or instead of you need just match or no match Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
syno Posted March 31, 2009 Author Share Posted March 31, 2009 Hi, can you give some examples like this String ..... = you need ... String ..... = you need ... String ..... = you need ... or instead of you need just match or no match Mega I am not entirely sure what you mean. I want to match 100,000 (with a comma). If I use the following code (without the comma) it works, ie MsgBox(0, "SRE Example 3 Result", StringRegExp('100000','(^|[^1][^0])1{1}0{5}([^1][^0]|$)')) How do i match 100,000 with 100,000 ? Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 31, 2009 Share Posted March 31, 2009 I need to understand what should match and what shouldn't so that I can create the correct pattern. so : 100,000 match 100000 should not match? 123,098 mtach? so it is always 3 digits a , and then again 3 digits? Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Ascend4nt Posted March 31, 2009 Share Posted March 31, 2009 You have to provide more context than that if you need to find a string inside others. With what you gave, you can do something as easily as this to grab that whole number: MsgBox(0, "SRE Example 3 Result", StringRegExp('100000','[\d,]+')) My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
syno Posted April 1, 2009 Author Share Posted April 1, 2009 I need to understand what should match and what shouldn't so that I can create the correct pattern. so :100,000 match100000 should not match?123,098 mtach?so it is always 3 digits a , and then again 3 digits?MegaHi thereOnly 100,000 should matchThanks Link to comment Share on other sites More sharing options...
Authenticity Posted April 1, 2009 Share Posted April 1, 2009 \b100,000\b Link to comment Share on other sites More sharing options...
Xenobiologist Posted April 1, 2009 Share Posted April 1, 2009 Hi, you can also do a string compare If $var == "100,000" Then ... or RegExp with \b like above which means word boundaries. Or if StringInStr ... which means the string is in the string not the string is 100 % the same. There are so many possibilities to do this "easy" job Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
GEOSoft Posted April 1, 2009 Share Posted April 1, 2009 Hi,you can also do a string compare If $var == "100,000" Then ... or RegExp with \b like above which means word boundaries. Or if StringInStr ... which means the string is in the string not the string is 100 % the same. There are so many possibilities to do this "easy" jobMegaThis seems to be a very common situation lately. "How do I use StringRegExp to do such and such?" , when there are other ways to do it. What people don't seem to realize is that RegExps, although more versatile, are generally slower than the normal string functions. When working with strings where there will be no variation in the string then you are better off using the normal functions such as StringInStr() or StringReplace(). 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 More sharing options...
Authenticity Posted April 1, 2009 Share Posted April 1, 2009 (edited) StringRegExp use internal optimizations that makes this function so fast and so versatile. If it's just to search for 100,000 in 11100,000TTT___ then it's probably way better to use StringInStr but if you want just 100,000 and nothing but it, RegExp is a good choice.Edit: By the way, StringRegExp use sort of StringInStr optimization where there is a literal text but using \d{3},\d{3} for example won't save you anything but allow you to match better than StringInStr. Edited April 1, 2009 by Authenticity Link to comment Share on other sites More sharing options...
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