Filter the data with powershell

Hello Guys,

I want find a way to filter the name form data with powershell. but I am not good at the regular expression, could someone have any idea about it?

2022-01-18 13:44 张三 (Henry) (12345678901) 审批通过,2022-01-15 16:52 系统 自动提交给 张三 (Henry) (12345678901)
2022-02-02 00:09 Richard Bob (14563123456) 审批超时自动通过,2022-01-18 15:59 系统 自动提交给 Richard Bob (14563123456)

I want to get this.

张三 (Henry)
Richard Bob (14563123456)

My idea is remove the first 17 characters which mean remove 2022-01-18 13:44
and remove Sapce (1*characters which mean remove * (12345678901) 审批通过,2022-01-15 16:52 系统 自动提交给 张三 (Henry) (12345678901)` It can work in excel, but I don’t know how to work in powershell.

Do you have headers in the table ? if so you can try using ConvertFrom-StringData.

or ConvertFrom-String using teamplates.

1 Like

Hello Kvprasoon,

Thank you!
It works.
That is easier than regular expression to get the data.

$str="2022-01-18 13:44 张三 (Henry) (12345678901) 审批通过,2022-01-15 16:52 系统 自动提交给 张三 (Henry) (12345678901)"|ConvertFrom-String
$str.p3+" "+$str.p4

By the way the regular expression way is

$str="2022-01-18 13:44 张三 (Henry) (12345678901) 审批通过,2022-01-15 16:52 系统 自动提交给 张三 (Henry) (12345678901)"
$pattern="(?<=\d{2}\:\d{2} )[^系统].*?(?= \(\d{11}\))"
$str -match $pattern
$matches.Values
1 Like