Regex is not valid

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Tony Antony Tony Antony 5 months ago.

  • Author
    Posts
  • #64423
    Profile photo of Tony Antony
    Tony Antony
    Participant

    Hello,

    I'm getting this message below, and I'm not sure what is causing the issue because I have another string that starts with "[UserColor]" and "[MembersOf-17]", both of which also have a "[", and it works fine.

    The regular expression pattern [MembersOf-7] is not valid.
    At \\hqfs1\Users\tantony\PowerShell\CalenderGroup\Calender.ps1:156 char:14
    + $Read_INI = $Read_INI -replace("$Items","$Replace")
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: ([MembersOf-7]:String) [], RuntimeException
    + FullyQualifiedErrorId : InvalidRegularExpression

    Thank you,

    Tony

  • #64429
    Profile photo of Don Jones
    Don Jones
    Keymaster

    [ is a special character. You need to escape it as \[ if you mean to use it literally.

    [UserColor] is being read as "any character that is U, s, e, r, C, o or l." In regex, [] represents a set or range.

  • #64432
    Profile photo of Tony Antony
    Tony Antony
    Participant

    Thank you Don.

    -cmatch "^\["

    , I do have the escape on "["

    I also found out that it will only happen if I delete the last "email" from a calendar group. Just need to figure out that now.

    Thanks,

You must be logged in to reply to this topic.