Trong Posted January 8, 2016 Author Posted January 8, 2016 For the best, I'll use UBound()But asked, so I wanted to know a way to answer my questions. Regards,
Trong Posted January 8, 2016 Author Posted January 8, 2016 I know your problem is solved, but maybe you can modify your regex to add a blank value at the first position of your returned array.Here is the trick :#Include <Array.au3> $string = "This is a string with seven words" $aWords = StringRegExp($string, "(?|^()|(\w+))", 3) $aWords[0] = UBound($aWords) - 1 _ArrayDisplay($aWords)You can note the empty group ^() which captures an empty value once. It's the first value of the returned array, so you can set it to UBound($array) - 1How to add a blank value at the first position ?Local $sArray = StringRegExp("-(A))-(B))-", "(?si)\Q(\E(.*?)(?=\Q)\E)", 3) ;~ $sArray[0] = UBound($sArray) - 1 If IsArray($sArray) Then ;~ For $i = 1 To $sArray[0] For $i = 0 To UBound($sArray) - 1 ConsoleWrite($sArray[$i] & @CRLF) Next Else ConsoleWrite("E: " & @error & " > " & $sArray & @CRLF) EndIf Regards,
Danp2 Posted January 9, 2016 Posted January 9, 2016 Haven't tested it, but couldn't you use _ArrayAdd to resize the array and then _ArrayPush to add the size value into the first position? Latest Webdriver UDF Release Webdriver Wiki FAQs
jguinch Posted January 9, 2016 Posted January 9, 2016 (edited) @Trong :Local $sArray = StringRegExp("-(A))-(B))-", "(?si)(?|^()|\Q(\E(.*?)(?=\Q)\E))", 3)Edit : where did you find the regex ? Edited January 9, 2016 by jguinch Trong 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
mikell Posted January 10, 2016 Posted January 10, 2016 @jguinchThis could be done simpler #Include <Array.au3> $string = "This is a string with seven words" $aWords = StringRegExp($string, "^|\w+", 3) $aWords[0] = UBound($aWords) - 1 _ArrayDisplay($aWords) Trong 1
jguinch Posted January 10, 2016 Posted January 10, 2016 I know mikell, I just replied to #22 I don't really understand the sense of his regex... Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
mikell Posted January 10, 2016 Posted January 10, 2016 jguinch,I was just replying to your post #16 about the generic creation of a blank $array[0] using regex BTW this regex in post #22 is strictly the one used by _StringBetween() , extracted from the includeIt could make sense if \Q...\E was needed to escape complicated strings - obviously not the case in the example the OP provided
jguinch Posted January 10, 2016 Posted January 10, 2016 OK, thanks. I usally use \Q..\E, but now, I don't understand why the regexp in #22 works... Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Trong Posted January 10, 2016 Author Posted January 10, 2016 Thanks for two head great, with me regexp as blind. Regards,
mikell Posted January 10, 2016 Posted January 10, 2016 OK, thanks. I usally use \Q..\E, but now, I don't understand why the regexp in #22 works...You certainly introduced a typo in your copy/paste #Include <Array.au3> ;Local $sArray = StringRegExp("-(A))-(B))-", "(?si)\Q(\E(.*?)(?=\Q)\E)", 3) Local $sArray = StringRegExp("-(A))-(B))-", "(?si)\((.*?)(?=\))", 3) _ArrayDisplay($sArray)
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