![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | How to make regex case insensitive I have the following code in a script I'm writing. The problem I'm having is it that it's not picking up text which doesn't match the case used in the regex e.g. 'ERROR' is not being matched whereas 'error' is. $Pattern = [regex]"error|warning|fault" $Match = $Pattern.Match($someText) while ($Match.Success) { $someText = $someText.replace($Match.Groups[0].Value, "") $Match = $Match.NextMatch() } The question is how do I modify the above code to make the regex ignorecase? Is there a flat I can set somewhere? Thanks |
My System Specs![]() |
| | #2 (permalink) |
| | Re: How to make regex case insensitive $Pattern = [regex]"(?i)error|warning|fault" -- Kiron |
My System Specs![]() |
| | #3 (permalink) |
| | Re: How to make regex case insensitive On Nov 7, 8:44 pm, "Kiron" <Ki...@xxxxxx> wrote: Quote: > $Pattern = [regex]"(?i)error|warning|fault" > > -- > Kiron |
My System Specs![]() |
| | #4 (permalink) |
| | Re: How to make regex case insensitive <stephenodonoghue@xxxxxx> wrote in message news:1194467647.744092.192220@xxxxxx Quote: > I have the following code in a script I'm writing. The problem I'm > having is it that it's not picking up text which doesn't match the > case used in the regex e.g. 'ERROR' is not being matched whereas > 'error' is. > > $Pattern = [regex]"error|warning|fault" > $Match = $Pattern.Match($someText) > while ($Match.Success) > { > $someText = $someText.replace($Match.Groups[0].Value, "") > $Match = $Match.NextMatch() > } > > The question is how do I modify the above code to make the regex > ignorecase? Is there a flat I can set somewhere? [regex]::Replace($someText, "(?i)error|warning|fault", "") -- Keith |
My System Specs![]() |
| | #5 (permalink) |
| | Re: How to make regex case insensitive Also... $sometext -replace "error|warning|fault" ![]() -- Kiron |
My System Specs![]() |
| | #6 (permalink) |
| | Re: How to make regex case insensitive "Kiron" <Kiron@xxxxxx> wrote in message news:7963BA17-66DD-4DF8-A78E-42A2E0E068D1@xxxxxx Quote: > Also... > > $sometext -replace "error|warning|fault" > > ![]() -- Keith |
My System Specs![]() |
| | #7 (permalink) |
| | Re: How to make regex case insensitive Keith Hill [MVP] wrote: Quote: > "Kiron" <Kiron@xxxxxx> wrote in message > news:7963BA17-66DD-4DF8-A78E-42A2E0E068D1@xxxxxx Quote: > > Also... > > > > $sometext -replace "error|warning|fault" > > > > ![]() > Yeah, even better. :-) > > -- > Keith |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| regex help | PowerShell | |||
| Regex | PowerShell | |||
| regex help | PowerShell | |||
| Regex Help | .NET General | |||
| regex | PowerShell | |||