On Tue, Nov 15, 2005 at 10:39:19PM -0500, Leonard Burton wrote: > HI Curt, > > Thanks for the reply, > > > What does a amateur radio callsign look like? And in what context > > are you trying to parse this callsign? > > Basically here is the regex I used (I am not the best with regexes): > > $pattern = "/^[0-9]?[A-Z]{1,2}[0-9][A-Z]{1,3}/"; > > Here are how they look > W1W > W1AW > WA1W > AD4HZ > N9URK > WB6NOA > 4N1UBG
Ok, so i can conclude so far we have alpha numeric chars minimum of 3 chars up to 6, this would make a regex: /[A-Z0-9]{3,6}/ I would assume however that the first char (or two) probably signifies the location of the callsign and based on the location a certain pattern is needed. > > I guess this would be better? > > $pattern = "/^"; > $pattern .= "([0-9][A-Z][0-9][A-Z]{3})|"; //4N1UBG > $pattern .= "([A-Z][0-9][A-Z]{1,3})|"; //N9URK, W1AW, W1W > $pattern .= "([A-Z]{2}[0-9][A-Z]{1,3})"; //WB6NOA, AD4HZ, WA1W > $pattern .= "/"; > > I am still trying to master regexes. Is there a better way to do this? For one trying to master regex's you seem to have a good grasp on it. If this pattern works according to the specs of a callsign, it should work fine. You could try to combine the regex into one statment (without the | condition) but that would make the regex rather ugly. One thing i would suggest, although probably a minor issue considering how long the string is, is to make sure you put the most likely match in your first pattern to match. Curt. -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php