Fwd: [WEB4LIB] Call Number/Letter Regular Expressions?
Andy Lester
andy at petdance.com
Thu Jul 25 16:01:08 EDT 2002
> e.g. A user enters TK 421 into a search box, the regular expression figures
> out that is an LC number.
> A user enters 8675-3099 into a search, and the regular expression
> figures out that is an ISSN
(Aside to Blake: "Jenny, why aren't you at your post?")
You don't say what language you're using, but I'll assume Perl since
you're talking about regexes.
You're not really looking for regexes specifcally. What you want is to
know if a given string is one "type" of search term or another. Regexes
are probably not what you're looking for. They're just a tool.
Besides, a regex is really a boolean expression in this case. "Is this
an ISBN? Is this an LC number?"
ISSN is mighty easy: /^\d{4}-?\d{4}$/, but that's about the only gimme
you're gonna get.
What you may want to do is look at some of the modules to handle these.
Business::ISBN, for example, will return an error if you try to pass a
non-ISBN to its constructor, so that's a test of a sort. Or, you can
steal code from them. What we do in Business::ISBN is strip the dashes
and then match against /^\d{9}[0-9X]$/.
I hope this helps. If you're indeed working in Perl, sign up for
perl4lib.
xoxo,
Andy
--
'Andy Lester andy at petdance.com
Programmer/author petdance.com
Daddy parsley.org/quinn Jk'=~/.+/s;print((split//,$&)
[unpack'C*',"n2]3%+>\"34.'%&.'^%4+!o.'"])
More information about the Web4lib
mailing list