Play with Regex in Powershell

Welcome Forums General PowerShell Q&A Play with Regex in Powershell

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

Ron
 
Participant
2 years, 6 months ago.

  • Author
    Posts
  • #57416

    Participant
    Topics: 23
    Replies: 17
    Points: 1
    Rank: Member

    Hi all,

    I am new to Regex trying to learn about it. I have the below data.

    $Data = " 1.4G /ofs01/prod/FileStore_auto_1"

    The value in 1.4G which Should never exceed more than 2.5G while the rest data will be same. Please help me to write a regex for the same.

  • #57418

    Participant
    Topics: 23
    Replies: 17
    Points: 1
    Rank: Member

    Executed this, it gave me 1.4 hope i m doing it in right way.

    [Regex]::Match($Command,"\d\.\d").Value

    • #57421

      Participant
      Topics: 1
      Replies: 1331
      Points: 1,680
      Helping Hand
      Rank: Community Hero

      If it does the job and that is what you expected ... thumbs up 😉

  • #57425
    Ron

    Participant
    Topics: 0
    Replies: 199
    Points: 2
    Rank: Member

    I have found this page quite valuable for developing and testing regex expressions.

    https://regex101.com/

    I'm sure there are others out there, but this one works for me. It allows you to test your expression with variations on your data to make sure you getting exactly the results you want, and displays diagnostic information on how it got those results.

    You didn't give a lot of information on how your data can vary, but my first instinct would be to make it as fuzzy as possible without failing. Your regex works as long as there is always one single digit, a period, and one single digit. I assume this is a storage size or something similar. You mentioned a max size, but can it be less? Will it always display a single decimal place? If its less than 1.0 will it display the leading zero? Is it always provided as "G" (gigabytes?)? And so on.

    Edit: Fixed link

  • #57428

    Participant
    Topics: 8
    Replies: 1190
    Points: 639
    Helping Hand
    Rank: Major Contributor

    Ron, missing your "this page" link

    • #57430
      Ron

      Participant
      Topics: 0
      Replies: 199
      Points: 2
      Rank: Member

      Looks like the link prompter doesn't automatically provide the url as the text if you leave the text blank. I updated it. Thanks

The topic ‘Play with Regex in Powershell’ is closed to new replies.

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