bash regex with shopt -s extglob -


I want to validate input to be like the following:

  nnn day NNN hours NNN minutes NNN.NNN seconds  

, and this should be a negative value, hence prefixed with - , and multiple choice is optional.

My script has shopt -s extglob , and I am using it:

  while reading; [[$ REPLY = ~ ^ - [[Points:]] {1,3} + [[Space:]] {1} (day | | hour | minute | second?) $]] & Amp; Amp; Dumb "good" || Echo "BAD";  

How do I apply different rules for the second, that NNN.NNNN ?

Is there a better, cleaner way to specify this Reggae, which I am already doing?

Try the following expression:

  ^ - [[: ]] {1,3} (\ [[:: numerals:]] {1,4}.) [[Space:]] ?? (Days | hours | minutes? | Seconds?) $  

You do not need to specify {1} for space.


If you want the decimal only for seconds, then this will be something wrong (you can change \ d with [[Space:]] ):

  ^ - \ D {1,3} ((\.? \ {{0}}? \ Ssecond | \ s (days | hours | minutes))? $  

In this way, the pattern will be (if you want to make sure that all seconds values ​​should be decals, instead of \?? \ D Change {0,4} to \. \ D {1,4} ):

^ - [[Issue:]] {1 , 3} (([. [[:: number:]] {0}} [[: space:]] second | [[: space:]] (days | hours | minutes)) $?

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -