Register
It is currently Wed Apr 23, 2014 1:36 pm

Bash regex help


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Wed Oct 10, 2012 1:07 pm   

Joined: Mon Apr 27, 2009 2:24 pm
Posts: 9
I've been using the following regex below in a bash script on RHEL 5.5 using version
GNU bash, version 3.2.25(1)-release

I've tried using the script on RHEL 6.3 which uses GNU bash, version 4.1.2(1)-release

I assume there's been alot of changes to bash since that's quite a jump in revisions. I'm wondering if anyone can help me sort what might have to be modified in the code to make this work again.

If I enter an e-mail address in a simple format like:

user.user@test.com the scripts sees this as an invalid e-mail now, whereas before this would pass the regex.



Code:
echo Enter the users e-mail address.

read ADDRESS

if [[ "$ADDRESS" =~ "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$" ]] ; then
echo $?
echo Proceeding!!
else
echo $?
echo You entered an invalid e-mail address!!!
exit 1
fi
Code:


Top
 Profile  
 PostPosted: Wed Oct 10, 2012 5:52 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
hi,

don't put right hand side part (regex) inside quotes
Code:
$ mailA="user.user@test.com"
$ [[ $mailA =~ "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$" ]] && echo KO || echo ko
ko
$ [[ $mailA =~ ^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$ ]] && echo OK || echo ko
OK
lhs quoting is unneeded.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP