Regex question

Welcome Forums General PowerShell Q&A Regex question

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

2 years, 3 months ago.

  • Author
  • #62157

    Points: -19
    Rank: Member

    I am working with the following match statement:

    $folder -match "[A-Z][A-Z][A-Z][A-Z][A-Z0-9]_*"

    However, it does not work the way I would it expect to work. I would expect


    to be false, and


    to be true.

    Unfortunately, both arguments are true. How can I test if the 6th position is an underscore (_) and not anything else ?


  • #62158

    Points: 1
    Rank: Member

    This should do it:


    ^ marks the begin
    [A-Za-z] = All A-Z ad a-z
    {5} = 5 times [A-Za-z]
    [_] = an underscore

  • #62161

    Points: 1,375
    Helping Hand
    Rank: Community Hero
    $Regex = '[A-Z]{5}_.+'
    $folder1 -match $Regex
    $folder2 -match $Regex
  • #62164

    Points: -19
    Rank: Member

    Thanks, works like a charm!

The topic ‘Regex question’ is closed to new replies.

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