Regex question

This topic contains 3 replies, has 3 voices, and was last updated by  Simon M 9 months ago.

  • Author
    Posts
  • #62157

    Simon M
    Participant

    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

    $folder="ABCDE-SomeOtherText"

    to be false, and

    $folder="ABCDE_SomeOtherText"

    to be true.

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

    Thanks!

  • #62158

    Chris Bakker
    Participant

    This should do it:

    
        ^[A-Za-z]{5}_.+
    

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

  • #62161

    Olaf Soyk
    Participant
    $folder1="ABCDE-SomeOtherText"
    $folder2="ABCDE_SomeOtherText"
    $Regex = '[A-Z]{5}_.+'
    $folder1 -match $Regex
    $folder2 -match $Regex
  • #62164

    Simon M
    Participant

    Thanks, works like a charm!

You must be logged in to reply to this topic.