Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › [BASH| Regular Expressions - Help solving this one! Please -SOLVED
New Posts  All Forums:Forum Nav:

[BASH| Regular Expressions - Help solving this one! Please -SOLVED

post #1 of 5
Thread Starter 

Hi. so any regex kings here. this is the challange. the only reward is a very big thank you.

 

I am trying to write an expression that will accept a numerical value in the to a max of 2 characters a decimal and 4 characters    XX.XXXX however here is the tricky fun. It also needs to accept whole numbers up to 99 with or with out the decimal numbers. so accepted numbers that should pass would be like the following 

 

 

5

5.1

5.12

2.313

9.1023

12

99.9999

 

the fail would be anything greater then 2 places such as 100.xxxx or just 100 and higher.

 

 

Here is a one liner you can use to test your regex

 

TEST=(test number here); if [[ $TEST =~ ^[0-9]{1,2}(\.[0-9]{1,4})?$ ]]; then echo "pass"; else echo "fail"; fi

 

 

of coure the (test number here) is where you actually populate the number. abve is just one of the many versions of expressions ive tried to use to match. my main problem is i can get it to work with any format that is including the decimal point. If i just use whole numbers like 1 12 123 1234 those ALL pass when they need to fail if being greater then 2 characters.

 

 

If you are a folder and you are able to help me solve this regex i will donate 1 week worth of soliding folding from my rig in your name. thats in addition to my thanks.

 

if any more data is needed please feel free to ask. this is going to be used in a function for fat finger checks when entering in numberical values.


Edited by Trippen Out - 2/10/13 at 10:42am
    
CPUMotherboardGraphicsRAM
Intel I7 2600k Asus p8p67-Deluxe Zotac GTX780 6GB OC G-skill Ripjaws 1866 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 EVO 250 Samsung EVO 120 Western Digital 1TB Black Lite On 20x DVD RW 
CoolingOSOSOS
XSPC RayStorm + 360Extreme Rad Arch Linux Windows 8.1 x64 WindowsRE 
MonitorKeyboardPowerCase
Asus PB278Q ThermalTake Meka G1 Evga SuperNova 1000 P2 Xigmatek Elysium 
MouseMouse PadAudio
Logitec G500 Gaming Mouse Ultra Pad Fiio E-17 + ATH-M50 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel I7 2600k Asus p8p67-Deluxe Zotac GTX780 6GB OC G-skill Ripjaws 1866 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 EVO 250 Samsung EVO 120 Western Digital 1TB Black Lite On 20x DVD RW 
CoolingOSOSOS
XSPC RayStorm + 360Extreme Rad Arch Linux Windows 8.1 x64 WindowsRE 
MonitorKeyboardPowerCase
Asus PB278Q ThermalTake Meka G1 Evga SuperNova 1000 P2 Xigmatek Elysium 
MouseMouse PadAudio
Logitec G500 Gaming Mouse Ultra Pad Fiio E-17 + ATH-M50 
  hide details  
Reply
post #2 of 5
Works on my computer, only minor changes
mine
Code:
mine_______TEST=(test number here); if [[ $TEST =~ ^[0-9]{0,2}(\.[0-9]{0,4})?$ ]]; then echo "pass"; else echo "fail"; fi
yours_____$TEST=(test number here); if [[ $TEST =~ ^[0-9]{1,2}(\.[0-9]{1,4})?$ ]]; then echo "pass"; else echo "fail"; fi

snapshot2.png 294k .png file
Edited by tom.slick - 2/8/13 at 10:28pm
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
post #3 of 5
Thread Starter 

Thanks. Never thought about using 0,4. Im very new to regex. they can be a love hate at times it seams. I will have to put this through its paces. when i log back into my linux box.

    
CPUMotherboardGraphicsRAM
Intel I7 2600k Asus p8p67-Deluxe Zotac GTX780 6GB OC G-skill Ripjaws 1866 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 EVO 250 Samsung EVO 120 Western Digital 1TB Black Lite On 20x DVD RW 
CoolingOSOSOS
XSPC RayStorm + 360Extreme Rad Arch Linux Windows 8.1 x64 WindowsRE 
MonitorKeyboardPowerCase
Asus PB278Q ThermalTake Meka G1 Evga SuperNova 1000 P2 Xigmatek Elysium 
MouseMouse PadAudio
Logitec G500 Gaming Mouse Ultra Pad Fiio E-17 + ATH-M50 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel I7 2600k Asus p8p67-Deluxe Zotac GTX780 6GB OC G-skill Ripjaws 1866 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 EVO 250 Samsung EVO 120 Western Digital 1TB Black Lite On 20x DVD RW 
CoolingOSOSOS
XSPC RayStorm + 360Extreme Rad Arch Linux Windows 8.1 x64 WindowsRE 
MonitorKeyboardPowerCase
Asus PB278Q ThermalTake Meka G1 Evga SuperNova 1000 P2 Xigmatek Elysium 
MouseMouse PadAudio
Logitec G500 Gaming Mouse Ultra Pad Fiio E-17 + ATH-M50 
  hide details  
Reply
post #4 of 5
Thread Starter 
Quote:
Originally Posted by tom.slick View Post

Works on my computer, only minor changes
mine
Code:
mine_______TEST=(test number here); if [[ $TEST =~ ^[0-9]{0,2}(\.[0-9]{0,4})?$ ]]; then echo "pass"; else echo "fail"; fi
yours_____$TEST=(test number here); if [[ $TEST =~ ^[0-9]{1,2}(\.[0-9]{1,4})?$ ]]; then echo "pass"; else echo "fail"; fi

snapshot2.png 294k .png file

 

 

all my testing show it fits what i need. I can't believe i got my butt kicked by neglecting the zero. Thanks. As reward if you want ill install the folding client and donate one week solid time of folding in with whatever number ya want me to use.

    
CPUMotherboardGraphicsRAM
Intel I7 2600k Asus p8p67-Deluxe Zotac GTX780 6GB OC G-skill Ripjaws 1866 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 EVO 250 Samsung EVO 120 Western Digital 1TB Black Lite On 20x DVD RW 
CoolingOSOSOS
XSPC RayStorm + 360Extreme Rad Arch Linux Windows 8.1 x64 WindowsRE 
MonitorKeyboardPowerCase
Asus PB278Q ThermalTake Meka G1 Evga SuperNova 1000 P2 Xigmatek Elysium 
MouseMouse PadAudio
Logitec G500 Gaming Mouse Ultra Pad Fiio E-17 + ATH-M50 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel I7 2600k Asus p8p67-Deluxe Zotac GTX780 6GB OC G-skill Ripjaws 1866 
Hard DriveHard DriveHard DriveOptical Drive
Samsung 840 EVO 250 Samsung EVO 120 Western Digital 1TB Black Lite On 20x DVD RW 
CoolingOSOSOS
XSPC RayStorm + 360Extreme Rad Arch Linux Windows 8.1 x64 WindowsRE 
MonitorKeyboardPowerCase
Asus PB278Q ThermalTake Meka G1 Evga SuperNova 1000 P2 Xigmatek Elysium 
MouseMouse PadAudio
Logitec G500 Gaming Mouse Ultra Pad Fiio E-17 + ATH-M50 
  hide details  
Reply
post #5 of 5
Fold for Team Number: 37726, Team Name: Overclock.net, under your own name and I will be happy:thumb:.
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
Core I7
(13 items)
 
  
CPUMotherboardGraphicsRAM
I7 920 rev. D0 @ 4.26Ghz EVGA X58 SLI EVGA GTX 285 OCZ XMP 3x2Gb (pc3 12800) 
Hard DriveOptical DriveOSMonitor
Western Digital Caviar Black 640Gb x 2 LG GH22LS30 openSuse 12.1 x64 HP F2105 
PowerCase
CORSAIR 850TX Cooler Master ATCS 840 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Linux, Unix
Overclock.net › Forums › Software, Programming and Coding › Operating Systems › Linux, Unix › [BASH| Regular Expressions - Help solving this one! Please -SOLVED