Use of -match

Welcome Forums General PowerShell Q&A Use of -match

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years, 2 months ago.

  • Author
  • #5666

    Points: 0
    Rank: Member

    by rambog at 2013-03-15 06:57:51

    I am trying to do a simple comparison. At the 6th character of a string, I am trying to determine if it contains the integer "1". There seems to a plethora of examples on how to perform more complex matches by issuing the command "help about_reg*" in powershell or consulting Nothing is evident for my instance in all these examples and I cannot seem to derive if from the examples given. I have tried -match ".....1*" but when I peform the -match ".....2*" it gives me the same result. Please let me know how I can specify a match on a particular integer which would be the 6th character in a string.

    by MasterOfTheHat at 2013-03-15 07:06:27

    Since you are looking for a specific character at a specific location in a string, just treat the string like an array:
    PS C:\Windows> $str = "abcde1ghi"
    PS C:\Windows> $str[5] -eq "1"
    PS C:\Windows> $str[5] -eq "2"

    by mjolinor at 2013-03-15 07:13:50

    Just for reference, a regex for that might look like this:
    $string = 'abcde1ghi'
    $string -match '^.{5}1'

The topic ‘Use of -match’ is closed to new replies.

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