Jump to content

Recommended Posts

Posted (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 by 123disconnect
Posted

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)

 

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

Posted

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)

 

Posted (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 by mikell
Posted

Sorry, I just did a quick answer. I did oversee the ||.
So, mikells solution is more correct.

 

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

Posted

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)

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...