Author Posts

November 11, 2016 at 12:00 pm

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.

November 11, 2016 at 12:09 pm

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


November 11, 2016 at 1:04 pm

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

November 11, 2016 at 2:05 pm

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

November 11, 2016 at 2:26 pm

Ron, missing your "this page" link

November 11, 2016 at 2:38 pm

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