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

有帮助吗?

解决方案

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

其他提示

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")')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top