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

 
Participant
2 years, 3 months ago.

  • Author
    Posts
  • #64423

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

    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

    Keymaster
    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

    Participant
    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.

    Thanks,

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

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