1

I am trying to use the following regex:

(?<=----Old-------\n)(((.+\n)+)\n*?)(?=__________________________________________)

to get multi lines betwords

----Old-------
250096 - LT Security Role: Read Only, 250032 - Sales VIC3, 250083 -
Security Role: Base Security Role, 250080 - Security Role: Payment
Allocation, 250058 - Security Role: TFM Sales Consultant, 250103 - Web
Fleet SuperUser

But the select-string is not returning anything.

I used https://regex101.com/ and https://www.regexpal.com/ and the Regex is working as expected.

could you please help.

$ModifyOldRegex = "(?<=----Old-------\n)(((.+\n)+)\n*?)(?=__________________________________________)"    
$Description | Select-String  -Pattern $ModifyOldRegex.matches.Value

enter image description here

  • try this: select-string -pattern $ModifyOldRegex -AllMatches | % { $_.Matches } | % { $_.Value } – SimonS Feb 1 '18 at 14:07
0

Finally I found the problem:

1- Use get-Content -Raw for the \n to work // I am not sure why

2- Changed the Regex to

"(?<=----Old-------)((.+\n)+)(?=__________________________________________)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.