JackDinn Posted May 6, 2009 Share Posted May 6, 2009 (edited) 2 hours , much reading , head ache.could someone please tel me where i can learn regular expressions iv read the AI help & the http://www.autoitscript.com/autoit3/pcrepattern.html page but there just dont seem to be a beginning its like it starts at the most complicated part.all i want to do is (this is a exampled just for ease in explanation) find all word with the letter "a" $string="Mary had a little lamb"and i want $string[1]="Mary"$string[2]="had"$string[3]="a"$string[4]="lamb"well something like that , duno if its a 0 based array or if and of the array positions contain other info like the array size or something else but you get the idea.iv tried StringRegExp($string,"\s(.*?)a(.*?)\s",1) i was hoping it meant "(space)+(any chrs)+"a"+(any chrs)+(space)" but it's not right, and it dont even start to include the first and last words which dont have a space before or after. i'll keep looking in a while just after my head stops the high pitch squealing sound Edited May 6, 2009 by JackDinn Thx all,Jack Dinn. JD's Auto Internet Speed Tester JD's Clip Catch (With Screen Shot Helper) Projects :- AutoIt - My projects My software never has bugs. It just develops random features. :-D Link to comment Share on other sites More sharing options...
Valuater Posted May 6, 2009 Share Posted May 6, 2009 Maybe... #include <Array.au3> $string = "Mary had a little lamb" $Spaces = StringSplit($string, " ") Global $array[UBound($Spaces)] $Items = 0 For $x = 1 To $Spaces[0] If StringInStr($Spaces[$x], "a") Then $Items += 1 $array[$Items] = $Spaces[$x] EndIf Next _ArrayDisplay($array) 8) Link to comment Share on other sites More sharing options...
JackDinn Posted May 6, 2009 Author Share Posted May 6, 2009 yea but im specificity wanting to look at StringRegExp, i already have it working that way but after looking at StringRegExp today i went back to this script to c if i could tidy it up a little and also give me some experience of the use of StringRegExp. maybe im wrong (probably) in the way it works but it looked to me that it would return an array of all the words with just one line of code. cheers. Thx all,Jack Dinn. JD's Auto Internet Speed Tester JD's Clip Catch (With Screen Shot Helper) Projects :- AutoIt - My projects My software never has bugs. It just develops random features. :-D Link to comment Share on other sites More sharing options...
Authenticity Posted May 6, 2009 Share Posted May 6, 2009 #include <Array.au3> Dim $sText = _ '2 hours , much reading , head ache.' & @CRLF & 'could someone please tel me where i can' & _ 'learn regular expressions iv read the AI help & the http://www.autoitscript.com/autoit3' & _ '/pcrepattern.html page but there just dont seem to be a beginning its like it starts at' & _ 'the most complicated part.' & @CRLF & _ 'all i want to do is (this is a exampled just for ease in explanation)' & @CRLF & _ 'find all word with the letter "a"' & @CRLF & '$string="Mary had a little lamb"' & @CRLF & _ 'and i want' & @CRLF & @CRLF &'$string[1]="Mary"' & @CRLF & '$string[2]="had"' & @CRLF & _ '$string[3]="a"' & @CRLF & '$string[4]="lamb"' & @CRLF & 'well something like that , duno ' & _ 'if its a 0 based array or if and of the array positions contain other info like the array' & _ 'size or something else but you get the idea.' & @CRLF & 'iv tried StringRegExp($string,"\' & _ 's(.*?)a(.*?)\s",1) i was hoping it meant "(space)+(any chrs)+"a"+(any chrs)+(space)" but' & _ 'it''s not right, and it dont even start to include the first and last words which dont ' & _ 'have a space before or after.' & @CRLF & @CRLF & @CRLF & _ 'i''ll keep looking in a while just after my head stops the high pitch squealing sound' Dim $sPattern = '(?i)\b(\w*?a\w*)\b' Dim $aMatch = StringRegExp($sText, $sPattern, 3) If IsArray($aMatch) Then _ArrayDisplay($aMatch) Link to comment Share on other sites More sharing options...
JackDinn Posted May 6, 2009 Author Share Posted May 6, 2009 wicked, now all i have to do is find how to learn this stuff but thats great for what i need for now so thx. Thx all,Jack Dinn. JD's Auto Internet Speed Tester JD's Clip Catch (With Screen Shot Helper) Projects :- AutoIt - My projects My software never has bugs. It just develops random features. :-D Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 6, 2009 Share Posted May 6, 2009 Hi, this should also work : '\w*[aA]\w*' 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...
JackDinn Posted May 7, 2009 Author Share Posted May 7, 2009 yea it does, all i have to do now is to understand why '\w*[aA]\w*' works and '(?i)\b(\w*?a\w*)\b' works and how they work. thx for the input. Thx all,Jack Dinn. JD's Auto Internet Speed Tester JD's Clip Catch (With Screen Shot Helper) Projects :- AutoIt - My projects My software never has bugs. It just develops random features. :-D Link to comment Share on other sites More sharing options...
Authenticity Posted May 7, 2009 Share Posted May 7, 2009 (edited) Both will achieve the goal in different ways. The first '\w*[aA]\w*' will match up to the last word character (i.e [0-9A-Za-z_]) backtrack to the first a or A character (actually it's the last but it's the first in reverse order), if no match it'll backtrack the whole word and start again at the next character over and over until a new match is possible, which is quite not big deal with tiny text sections. The second will try to do it differently by checking always the next character after \w*? could match and if it can't find it'll consume another character, checking again the next one up to the end of the word, backtracking, now \b can't match at the middle of a word so it'll bump-along (move the entire expression on the next location in the string).... so I'll try to demonstrate both:expandcollapse popupRegular Expression: /(?C)\w*(?C)[aA](?C)\w*/ String: Google PCRE version 7.8 2008-09-05 /(?C)\w*(?C)[aA](?C)\w*/ Google 0 ^ \w* 0 ^ ^ [aA] 0 ^ ^ [aA] 0 ^ ^ [aA] 0 ^ ^ [aA] 0 ^ ^ [aA] 0 ^^ [aA] 0 ^ [aA] 0 ^ \w* 0 ^ ^ [aA] 0 ^ ^ [aA] 0 ^ ^ [aA] 0 ^ ^ [aA] 0 ^^ [aA] 0 ^ [aA] 0 ^ \w* 0 ^ ^ [aA] 0 ^ ^ [aA] 0 ^ ^ [aA] 0 ^^ [aA] 0 ^ [aA] 0 ^ \w* 0 ^ ^ [aA] 0 ^ ^ [aA] 0 ^^ [aA] 0 ^ [aA] 0 ^ \w* 0 ^ ^ [aA] 0 ^^ [aA] 0 ^ [aA] 0 ^ \w* 0 ^^ [aA] 0 ^ [aA] 0 ^ \w* 0 ^ [aA] Edited May 7, 2009 by Authenticity Link to comment Share on other sites More sharing options...
JackDinn Posted May 7, 2009 Author Share Posted May 7, 2009 your a good chap for taking the time to display all that for me, i can see the difference between them now in theory it's the syntax i just dont have an understanding of eg what do the ( ), { }, [ ] brackets represent iv read a lot but still dont even understand how to use and what they are ? what i really need is somewhere other than http://www.autoitscript.com/autoit3/pcrepattern.html that starts really simple and walks me through is a step at a time, i'll have a hunt with google and c what i can find.but thx to your help (both of you) i have done what i was trying to do in my script but im sure i'll be wishing i had actually learned this stuff properly soon enough as i cant keep asking each time i have a different pattern required.looking through the forum it seems there a lot of peeps in a similar situation to me on this one, maybe someone should do a beginners guide to StringRegExp & pcrepattern matching. if i find a good start out site i'll drop a link.Thx again. Thx all,Jack Dinn. JD's Auto Internet Speed Tester JD's Clip Catch (With Screen Shot Helper) Projects :- AutoIt - My projects My software never has bugs. It just develops random features. :-D Link to comment Share on other sites More sharing options...
Authenticity Posted May 7, 2009 Share Posted May 7, 2009 The in-depth view of the internals of RegExp is not for a 20 section tutorial but a book so you should read a book and practice to get a decent understanding of it. You can read this tutorial http://www.regular-expressions.info/tutorial.html which I find to be pretty neat. If you want more, read a book. Link to comment Share on other sites More sharing options...
JackDinn Posted May 7, 2009 Author Share Posted May 7, 2009 cheers Thx all,Jack Dinn. JD's Auto Internet Speed Tester JD's Clip Catch (With Screen Shot Helper) Projects :- AutoIt - My projects My software never has bugs. It just develops random features. :-D 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