How to Extract Specific Text with Regex

I have a Command Like this

Get-DlpDetailReport -DlpCompliancePolicy “Default DLP Monitoring Policy | Exchange Only” -DlpComplianceRule “Official Label Monitoring” -StartDate “07/05/2022 00:00” -EndDate “07/05/2022 23:59” -PageSize 5000 -EventType DLPRuleHits | where {$_.DlpComplianceRule -eq “Official Label Monitoring”} | Select-Object Date, Title, Actor, DlpComplianceRule, Recipients, AttachmentNames | Export-Csv “OfficialLabelMonitoring5.csv”

I want to only extract - OfficialLabelMonitoring5.csv

How Can I do this ?

@Ishan_Shelke
first split string with | pipe symbol and get last value from string array, after that you have only Export-Csv “OfficialLabelMonitoring5.csv” this then use substring method .

Hi @Ishan_Shelke

System.Text.RegularExpressions.Regex.Match(YourString,"\S+.csv").Tostring

Regards
Gokul

Can you also show how to extract

Data classification - NCR.xlsx

from

D:\Uipath\AIpReports\Confidential Label Monitoring\Data classification - NCR.xlsx

Hi @Ishan_Shelke

Try this out

System.Text.RegularExpressions.Regex.Match(YourString,"\S+.csv|\S+.xlsx|\S+.pdf|\S+.xls").Tostring

Regards
Gokul

I am only getting Output as

NCR.xlsx

I want : Data classification - NCR.xlsx

Hi @Ishan_Shelke

Can you provide us the input

Regards
Gokul

Hi @Ishan_Shelke

Try out this expression

System.Text.RegularExpressions.Regex.Match(YourString,"Data\s\S.+").Tostring

Regards
Gokul

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.