Play with Regex in Powershell

This topic contains 5 replies, has 4 voices, and was last updated by  Ron 1 year, 8 months ago.

  • Author
  • #57416

    Amar Helloween

    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

    Amar Helloween

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


    • #57421

      Olaf Soyk

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

  • #57425


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

    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

    Rob Simmers

    Ron, missing your "this page" link

    • #57430


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

You must be logged in to reply to this topic.