andybiochem Posted July 30, 2008 Share Posted July 30, 2008 (edited) Hi!I'm trying to get my head around regular expressions, but it's doing my nut!say I wanted to match the following list of strings:12,25.5,ABC1,97,Nam33,100,Zbut NOT:12,25.5,ABC,zzz(notice the ",zzz" bit at the end)how do I do this with stringregexp?So far I've got:"([0-9]{1,}[,][0-9]{1,}[.]?([0-9]{1,})?[,][[:alnum:]]{1,})"but this sees a match and returns it. I want the inputted string to match exactly the reg exp given....if there's more data in the string than specified in the reg exp I want it to fail.Thanks in advance for any help!! Edited July 30, 2008 by andybiochem - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
Xenobiologist Posted July 30, 2008 Share Posted July 30, 2008 Hi, you need to think of a regular method of your strings. Match all, but not if they end with zzz? Is that the rule? 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...
andybiochem Posted July 30, 2008 Author Share Posted July 30, 2008 (edited) Hi, you need to think of a regular method of your strings. Match all, but not if they end with zzz? Is that the rule? Mega Not just zzz, anything at all after the 3rd item. the way I'm thinking of my string to match is: [any integer][comma][any number including decimal places][comma][any word/number/both] if the whole string doesn't match this format then I want regexp to return = 0 but because it sees that format above within "12,25.5,ABC,zzz" it returns success (=1). I want it to look at the whole string, not just pick and choose where it finds matches mid-string. thanks for the reply tho! Edited July 30, 2008 by andybiochem - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
Xenobiologist Posted July 30, 2008 Share Posted July 30, 2008 Hi, try this: \d+,\d+[\.]*\d*,\w*(?=\s) 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...
Moderators SmOke_N Posted July 30, 2008 Moderators Share Posted July 30, 2008 "(?s)(\d+,\d+\.*\d*,\w+)(?:\z|\s)" Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
andybiochem Posted July 30, 2008 Author Share Posted July 30, 2008 Thank you both! SmOke_N yours seems to work for every example i've tried, so I'll go with that. Cheers! - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
andybiochem Posted July 30, 2008 Author Share Posted July 30, 2008 I eventually found some examples that wouldn't work with Smoke's reg exp So this is how I managed to get it to work: $string = "3,25.0,Text here" ;this should match ;$string = "zzz,123,32.33,Text Here" ;this shouldn't match ;$string = "123,32.33,Text Here...." ;this shouldn't match ;----- check string for reg exp ----- $aMatches = StringRegExp($string,"(?:\D*)(\d+,\d+.?\d?,[\w ]*)(?:\W*)",1) ;----- if no matches found... ----- If @error = 1 Then MsgBox(0,"","String format not correct") Exit EndIf ;----- if match found not the same as original string... ----- If $aMatches[0] <> $string Then MsgBox(0,"","String format not correct") Exit EndIf ;----- other-wise good match ----- MsgBox(0,"","String format good!!!") The important bit was the second If>EndIf section. If the 'matched' string wasn't identical to the original string, then the StringRegExp has cherry-picked the match out of a different, longer, string....thus for the purpose I needed this was a false-positive. I want to know if the WHOLE string matches the reg exp. Maybe I've missed something obvious, but this is the only way I could find to get it to work. Just thought I'd share. - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
Gigglestick Posted July 30, 2008 Share Posted July 30, 2008 (edited) Yours: (?:\D*)(\d+,\d+.?\d?,[\w ]*)(?:\W*)Smoke_N's: (?s)(\d+,\d+\.*\d*,\w+)(?:\z|\s)These don't match. You said you were going to use Smoke_N's. Does it work with his? You have a workaround. I'm just curious. Edited July 30, 2008 by c0deWorm My UDFs: ExitCodes Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 30, 2008 Moderators Share Posted July 30, 2008 (edited) I eventually found some examples that wouldn't work with Smoke's reg exp So this is how I managed to get it to work: $string = "3,25.0,Text here" ;this should match ;$string = "zzz,123,32.33,Text Here" ;this shouldn't match ;$string = "123,32.33,Text Here...." ;this shouldn't match ;----- check string for reg exp ----- $aMatches = StringRegExp($string,"(?:\D*)(\d+,\d+.?\d?,[\w ]*)(?:\W*)",1) ;----- if no matches found... ----- If @error = 1 Then MsgBox(0,"","String format not correct") Exit EndIf ;----- if match found not the same as original string... ----- If $aMatches[0] <> $string Then MsgBox(0,"","String format not correct") Exit EndIf ;----- other-wise good match ----- MsgBox(0,"","String format good!!!") The important bit was the second If>EndIf section. If the 'matched' string wasn't identical to the original string, then the StringRegExp has cherry-picked the match out of a different, longer, string....thus for the purpose I needed this was a false-positive. I want to know if the WHOLE string matches the reg exp. Maybe I've missed something obvious, but this is the only way I could find to get it to work. Just thought I'd share. You changed the situation: Text<space>Here was not in your specs. Edit: You know, actually it would be MUCH better if you just posted the actual file you were trying to manipulate rather than trying to make scenarios. You leaving the slightest thing out changes an expression completely. Edited July 30, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
andybiochem Posted July 30, 2008 Author Share Posted July 30, 2008 You changed the situation: Text<space>Here was not in your specs. Yeah, my fault. should have said: [any integer][comma][any number including decimal places][comma][any words/numbers/Chr(32)s] Really appreciated the help though, really made me think about reg exp in a different way. - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
andybiochem Posted July 30, 2008 Author Share Posted July 30, 2008 You know, actually it would be MUCH better if you just posted the actual file you were trying to manipulate rather than trying to make scenarios. You leaving the slightest thing out changes an expression completely.It wasn't actually a file I was working on. The scenario was in fact one I had made....this reg exp was a way of checking a user's input was in the correct format (a format I had devised) and that they hadn't just typed in junk. - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
andybiochem Posted July 30, 2008 Author Share Posted July 30, 2008 (edited) Lol, found more faults. Now I'm working with: "(?:\D*)(\d+,\d+(.\d+)*,[\w ]*)(?:\W*)" @SmOke_N Is there a less draw-out way of doing this?: $string = "3,25.0,Text here" ;this should match ;$string = "zzz,123,32.33,Text Here" ;this shouldn't match ;$string = "123,32.33,Text Here...." ;this shouldn't match ;----- check string for reg exp ----- $aMatches = StringRegExp($string,"(?:\D*)(\d+,\d+(.\d+)*,[\w ]*)(?:\W*)",1) ;----- if no matches found... ----- If @error = 1 Then MsgBox(0,"","String format not correct") Exit EndIf ;----- if match found not the same as original string... ----- If $aMatches[0] <> $string Then MsgBox(0,"","String format not correct") Exit EndIf ;----- other-wise good match ----- MsgBox(0,"","String format good!!!") ...ignore the msgboxes they're just there to check correct returns. Edited July 30, 2008 by andybiochem - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
therks Posted July 31, 2008 Share Posted July 31, 2008 I haven't analyzed everything.. but have you tried using ^ and $ to match the start and end of a string? Just going off your first example of "[any integer][comma][any number including decimal places][comma][any word/number/both]" try this? ^\d+,\d+(\.\d+)?,[\w ]+$ My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
andybiochem Posted July 31, 2008 Author Share Posted July 31, 2008 I haven't analyzed everything.. but have you tried using ^ and $ to match the start and end of a string? Just going off your first example of "[any integer][comma][any number including decimal places][comma][any word/number/both]" try this? YES! That's it!! Thanks you! ^ and $ ...where on earth did they come from? lol! Can this be added to the help file? Their use is mentioned here: http://en.wikipedia.org/wiki/Regular_expression Thanks for everyone's help! much appreciated. - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar! Link to comment Share on other sites More sharing options...
therks Posted August 1, 2008 Share Posted August 1, 2008 I could have sworn they were in the documentation as they're pretty standard, but when I checked sure enough they aren't there. They are mentioned indirectly with the (?m) flag. There is a lot of stuff that RegEx is capable of that's not mentioned in the AutoIt doc's though. There's a link near the top of that page which links here though, which is a more detailed description of the RegEx syntax. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
ptrex Posted August 5, 2008 Share Posted August 5, 2008 @Saunders / andybiochem, Open the HELP file -> stringRegExp -> Enter Look for (?m) down the list. There you will find the ^ and $. Sorry for the late reply though. Running a bit late have to catch up. regards, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New 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