Home > Mobile >  PowerShell regex needed to capture a field data
PowerShell regex needed to capture a field data

Time:06-17

2022-05-02T09:36:07,034 INFO  [00000015] :AB-XXXXXXXXXXX@lllCORP - 3          %LET _CLIENTUSERID = 'crag';
2022-05-02T09:36:07,034 INFO  [00000015] :AB-XXXXXXXXXXX@GDLCORP - 3          %LET _CLIENTUSERID = 'Drkre';
2022-05-10T11:05:14,220 INFO  [00000015] :AB-XXXXXXXXXXX@FLLCORP - 3          %LET _CLIENTUSERID = 'Plgr2';
2022-05-10T11:05:14,220 INFO  [00000015] :AB-XXXXXXXXXXX@vLLCORP - 3          %LET _CLIENTUSERID = 'byref';
2022-05-10T11:05:14,220 INFO  [00000015] :AB-XXXXXXXXXXX@lLLCORP - 3          %LET _CLIENTUSERID = 'dfrg23';
2022-05-10T11:05:14,220 INFO  [00000015] :AB-XXXXXXXXXXX@XLLCORP - 3          %LET _CLIENTUSERID = 'FlogR1';

The expected outputs should look like below

crag
Drkre
Plgr2
byref
dfrg23
FlogR1

Thanks

CodePudding user response:

Okay, I'm assuming that the data is stored in a variable called $values and is an array where each entry of the array is an individual line, the following should extract your values as requested:

$values | % { [regex]::match( $_ , "(?<=')(. )(?=')" ) } | Select -ExpandProperty Value

If $values is just a string containing the data, you can use the following instead:

[regex]::matches($values, "(?<=')(. )(?=')" ) | Select -ExpandProperty Value
  • Related