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

Re: [Sheflug] Reg exp for V.I.A.G.R.A



And Lo! The Great Prophet " Chris Johnson" uttered these words of wisdom:
> Is there an easy way to write a reg exp to put in my mail filter that will
> take out all the viagras including those spaced with 0 or more other
> characters?
> v i a g r a
> v_I_a gra
> etc
>

In it's rawest form, it'd look summat like:

        [Vv][_ .]*[Ii][_ .]*[Aa][_ .]*[Gg][_ .]*[Rr][_ .]*[Aa]

Where [Vv] et al match either upper or lower case version of character,
and the other pattern matches all your seprators.

The [...] pattern basically means "match any character in this set", so
something like [BghQ] will match one of B, g, h or Q. The '*' that follows
means "match zero or more of the previous pattern", so [BghQ]* would match
B, BBBgQh, BghQ, Qh, QQQQQQQQQ, etc ... INCLUDING not matching it at all,
so "hello[QWER]*world" will match helloworld as well as
helloQQQQQQQQworld.

So we put all the seperator chars in there, in this case a space, an
underscore and a period (note that the period does /not/ need to be quoted
when inside [...]; it normally does as it's a special character).

Depending on what you use, you may have flags you can set with a regular
expression to say "ignore case", in which case, the simplest you'll get it
is:

        v[_ .]*i[_ .]*a[_ .]*g[_ .]*r[_ .]*a

Chris...

-- 
\ Chris Johnson                 \
 \ cej [at] nightwolf.org.uk          \
  \ http://cej.nightwolf.org.uk/  ~-----------------------------------+
   \ Redclaw chat - http://redclaw.org.uk - telnet redclaw.org.uk 2000 \____

___________________________________________________________________

Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html

  GNU the choice of a complete generation.