Pergunta

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

Foi útil?

Solução

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

Outras dicas

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")')
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top