Question

I am trying to compare strings like this:

'Backup Exec Alert: Job Success (Server: "AMSMGMT") (Job: "Ams-Daily-Back")' -match '(Server: "AMSMGMT") (Job: "Ams-Daily-Back")'

Which is returning false because I need to scape the wildcards e.g.

'/(Server: "AMSMGMT"/) /(Job: "Ams-Daily-Back"/)'

Question:

Is there any powershell function to find substrings ignoring wildcards/regex?

thank you very much

Était-ce utile?

La solution

Since you're doing a literal string match, -like might be a better choice than -match

'Backup Exec Alert: Job Success (Server: "AMSMGMT") (Job: "Ams-Daily-Back")' -like '*(Server: "AMSMGMT") (Job: "Ams-Daily-Back")'

True

Autres conseils

As previous answer, like is more appropriate but you could also use "Escape"

'Backup Exec Alert: Job Success (Server: "AMSMGMT") (Job: "Ams-Daily-Back")' -match [System.Text.RegularExpressions.Regex]::Escape('(Server: "AMSMGMT") (Job: "Ams-Daily-Back")')

Or C# contains method

'Backup Exec Alert: Job Success (Server: "AMSMGMT") (Job: "Ams-Daily-Back")'.Contains('(Server: "AMSMGMT") (Job: "Ams-Daily-Back")')
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top