Regex is not valid

Welcome Forums General PowerShell Q&A Regex is not valid

This topic contains 2 replies, has 2 voices, and was last updated by

2 years, 3 months ago.

  • Author
  • #64423

    Topics: 73
    Replies: 165
    Points: 65
    Rank: Member


    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,


  • #64429

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    [ 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

    Topics: 73
    Replies: 165
    Points: 65
    Rank: Member

    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.


The topic ‘Regex is not valid’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort