Re: regex expression help

Re: regex expression help

am 18.12.2007 23:21:11 von Gunnar Hjalmarsson

Tom.E.Ward@gmail.com wrote:
> I need to extract serial numbers from multiple text files. I have an
> expression that works fairly well, but the problem is some of the
> serial numbers are enclosed within quotes (both single and double) and
> I can't figure out a good way to get rid of the closing quote. The
> expression of have now is:
>
> /($matchString\s*[\:\=\-]\s*[\'\"]?)(([\w]+$)|(([\w]+)([^\w] )))/
>
> ($matchString contains {"serial number", "sn", "s/n", "serial num",
> etc.}

A backreference might be useful.

/$matchString\s*[:=-]\s*(['"]?)([\w]+)\1/

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl