123disconnect Posted December 15, 2015 Posted December 15, 2015 (edited) I have code$pattern = $str = "%abcd% = Section, hardwareID_1, hardwareID_2, ..... ,HardwareID_n" $array = StringRegExp( $str, $pattern, 3)Anyone help me with $pattern value I need $array is : $array[0] = 'abcd'$array[1] = 'HardwareID_1'$array[2] = 'HardwareID_2'.......$array[n] = 'HardwareID_n'No whitespace in all return string . (Sorry for my English)Thank you verymuch Edited December 15, 2015 by 123disconnect
Xenobiologist Posted December 15, 2015 Posted December 15, 2015 Maybe this way#include<array.au3> $pattern = '%(\w+)%|,\s*(\w+)' $str = "%abcd% = Section, hardwareID_1, hardwareID_2, ..... ,HardwareID_n" $array = StringRegExp($str, $pattern, 3) ConsoleWrite(_ArrayToString($array) & @CRLF) 123disconnect 1 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
ViciousXUSMC Posted December 15, 2015 Posted December 15, 2015 Works good Xeno except seems to to produce line extra array elements between the results.Probably can be fixed in the regex, but I would probably just strip it like this:#Include <Array.au3> #Include <StringConstants.au3> $sPattern = '%(\w+)%|,\s*(\w+)' $sString = "%abcd% = Section, hardwareID_1, hardwareID_2, ..... ,HardwareID_n" $aArray = StringRegExp($sString, $sPattern, $STR_REGEXPARRAYGLOBALMATCH) $sString2 = _ArrayToString($aArray, "|") $sString2 = StringReplace($sString2, "||", "|") $aArray2 = StringSplit($sString2, "|", $STR_NOCOUNT) _ArrayDisplay($aArray2) 123disconnect 1
mikell Posted December 15, 2015 Posted December 15, 2015 (edited) Please manage the character set [\w.#] depending on the syntax of the elements to get #include<array.au3> $pattern = '(?<=%|,)\s*([\w.#]+)' $str = "%abcd% = Section, hardwareID_#1, hardwareID_2, ..... ,HardwareID_n" $array = StringRegExp($str, $pattern, 3) _ArrayDisplay($array) Edited December 15, 2015 by mikell 123disconnect 1
Xenobiologist Posted December 15, 2015 Posted December 15, 2015 Sorry, I just did a quick answer. I did oversee the ||.So, mikells solution is more correct. 123disconnect 1 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
ViciousXUSMC Posted December 15, 2015 Posted December 15, 2015 mikell always got the regex I figured a non capture group of some sort would be the fix, mind explaining how come your regex does not produce the same blank elements as Xeno's is it the lookbehind? 123disconnect 1
jguinch Posted December 15, 2015 Posted December 15, 2015 Xenobiologist's regex works, but must be enclosed in a duplicate subpattern group :#include <array.au3> $pattern = '(?|%(\w+)%|,\s*(\w+))' $str = "%abcd% = Section, hardwareID_1, hardwareID_2, ..... ,HardwareID_n" $array = StringRegExp($str, $pattern, 3) _ArrayDisplay($array) Xenobiologist and 123disconnect 2 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
mikell Posted December 15, 2015 Posted December 15, 2015 Haha yes the 'force reset' thing does the trick The lookaround is not bad either 123disconnect 1
jguinch Posted December 15, 2015 Posted December 15, 2015 (edited) Yes, but more complex... Edited December 15, 2015 by jguinch 123disconnect 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
123disconnect Posted December 16, 2015 Author Posted December 16, 2015 ok. Thank ViciousXUSMC, mikell, jguinchThank all very much
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