String Matching Help

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 6 years, 5 months ago.

  • Author
  • #5384

    by dunagh at 2012-12-27 15:22:39

    Can someone tell me why...

    "PC" -match "."

    ...evaluates to True?


    by Klaas at 2012-12-28 00:22:39

    because -match does regular expression matching, and '.' is the wildcard for any character. With other operators that would be '?'.

    by nohandle at 2012-12-28 05:04:10

    [quote="Klaas"]because -match does regular expression matching, and '.' is the wildcard for any character.[/quote]
    For almost any character. By default it does not match new line characters.
    [quote="Klaas"]With other operators that would be '?'.[/quote]
    Frankly I am not sure how you meant this. Can you calrify please?
    The purpose of the '?' sign is to make the previous group optional hence, "pc?" would match both 'p' and 'pc'.

    To match the '.' as is. You have to escape the '.' (or any metacharacter) by backslash like so:
    'a.b' -match 'a\.b'

    Personally I use to refer any regex question.

    by Klaas at 2012-12-28 07:14:22

    I mean that "PC" -like "?C" would return TRUE, because it uses wildcard expressions, as most operators do (-equals, -contains, -gt, -lt,...),
    but -match and -replace use regular expressions.

    by nohandle at 2012-12-28 07:53:47

    Thanks Klass, now it is clear.

    [quote="Klaas"] -match and -replace [/quote]
    and also -split. 🙂

    by dunagh at 2013-01-08 08:25:53

    Thanks for the answer. I thought I had tried to escape the period without success but I must have done something wrong with my original attempt. The evaluations are now working as expected.

You must be logged in to reply to this topic.