Forum Moderators: coopster

Message Too Old, No Replies

Another Regex question

This has probably been addressed elsewhere...

         

Trav

8:59 pm on Aug 20, 2009 (gmt 0)

10+ Year Member



I am trying to write a regex that will FAIL if a character (the '@' symbol) has either not been entered, or if it's been entered more than once. Was trying with 'repetition' operators, but seems like that pertained to characters in consecutive order... I need to test the entire string and see if there's more than one '@' symbol anywhere, and if so, the match fails. What am I not getting here? Thanks in advance!

Trav

Gibble

9:31 pm on Aug 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Download expresso, best tool to test regular expressions

Having said that /[^@]*@{1}[^@]*/

AFS@ASDF@ADSF - fail
ASDF@asdf - pass
asdf@ - pass
@asdf - pass
asdfasdf - fail

Trav

10:51 pm on Aug 20, 2009 (gmt 0)

10+ Year Member



Cool, thanx Gibble. I will study this and see what I was not understanding.

g1smd

11:29 pm on Aug 20, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can make adsf@ and @adsf into FAIL by using + instead of * in the pattern.

That will require "one or more" instead of "zero or more" characters for the other parts.

Gibble

1:04 am on Aug 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, he did say "'@' symbol anywhere", so...I did anywhere. But yeah.

Trav

3:23 pm on Aug 21, 2009 (gmt 0)

10+ Year Member



yeah, I wasn't really going for perfection- just trying to grasp how to write a regex for that purpose... I did download Expresso, and I'm going to noodle around with that for a while.