[GRLUG] Bash regex
Robert Citek
robert.citek at gmail.com
Tue May 7 14:40:55 EDT 2013
On Tue, May 7, 2013 at 2:28 PM, Nathan Phillip Brink <binki at gentoo.org> wrote:
> Works for me:
>
> ohnobinki at ohnopublishing ~ $ a=2012-04
> ohnobinki at ohnopublishing ~ $ [[ $a =~ [0-9]{4}-[0-9]{2} ]]; echo $?
> 0
> ohnobinki at ohnopublishing ~ $ a=20a2-04
> ohnobinki at ohnopublishing ~ $ [[ $a =~ [0-9]{4}-[0-9]{2} ]]; echo $?
> 1
> ohnobinki at ohnopublishing ~ $ echo ${BASH_VERSION}
> 4.2.10(2)-release
Ditto. Bash does grouping, too:
$ a=2012-04 ; regex='([0-9]{4})-[0-9]{2}' ; [[ $a =~ ${regex} ]] ;
echo ${BASH_REMATCH[@]}
2012-04 2012
Regards,
- Robert
More information about the grlug
mailing list