[Tutor] Advanced String Search using operators AND, OR etc..
vince spicer
vinces1979 at gmail.com
Mon May 4 18:38:31 CEST 2009
Advanced Strings searches are Regex via re module.
EX:
import re
m = re.compile("(FDA.*?(approved|supported)|Ben[^\s])*")
if m.search(Text):
print m.search(Text).group()
Vince
On Mon, May 4, 2009 at 6:45 AM, Alex Feddor <alex.feddor at gmail.com> wrote:
> Hi
>
> I am looking for method enables advanced text string search. Method
> string.find() or re module seems no supporting what I am looking for. The
> idea is as follows:
>
> Text ="FDA meeting was successful. New drug is approved for whole sale
> distribution!"
>
> I would like to scan the text using AND and OR operators and gets -1 or
> other value if the searching elements haven't found in the text.
> Example 01:
> search criteria: "FDA" AND ( "approve*" OR "supported")
> The catch is that in Text variable FDA and approve words are not one after
> another (other words are in between).
> Example 02:
> search criteria: "Ben"
> The catch is that code sould find only exact Ben words not also words which
> that has firts three letters Ben such as Benquick, Benseek etc.. Only Ben is
> the right word we are looking for.
>
> I would really appreciated your advice - code sample / links how above can
> be achieved! if possible I would appreciated solution achieved with free of
> charge module.
>
> Cheers, Alex
> PS:
> A few moths ago I have discovered Python. I am amazed what all can be done
> with it. Really cool programming language..
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090504/88993fa6/attachment-0001.htm>
More information about the Tutor
mailing list