Re: Regex for Amateur Radio Callsigns

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Nov 16, 2005 at 12:25:22AM -0500, Leonard Burton wrote:
> HI Curt,
> > > 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}/
> 
> The only problem with this is that it would take "444" which is not a
> valid call.
> > > $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 .= "/";
> > >
> 
> > 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.
> 
> I am looking for a regex that I can use for both preg_split and
> preg_match.  I have not yet really learned how to do preg_splits yet. 
> I am still trying to figure out what in the world to do.   I have done
> some preg_splits and I know enought to know that if you have more than
> one set of () that will return on an expression then it will royally
> mess things up.

I guess the difference between a _match a _split is that a _match
is what you are looking for a _split is what is usually ignored
because you want to seperate the data based on the regex.  if you
use _split and want to know what the value was, then use the
PREG_SPLIT_DELIM_CAPTURE option for it, the array returned will
include the match that made the split to occur.

> 
> > 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.
> 
> Actually that is a good suggestion.  I can see how it would make
> things more efficent.  Should you order the whole expression in terms
> of how likely it is to get a result?
> (i.e. "/^(most)|(frequent)|(least)/")

yeah, i wouldn't consider myself that much of an expert on it but
from my understanding on matching the sooner the match the better.
That is usually why the anchor ^ is used in most expression, if
pcre knows it is a start of the line it doesn't have to do any
fuzzy matching, it knows exactly where to start.

What kind of context are you trying to match?

A paragraph that mentions a callsign:
  You can contact me at 4N1UBG, blah blah

or some sort of formated data:

  4N1UBG, me
  N9URK, someone
  ...


Curt.
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux