[Tutor] pattern searching

Shashwat Anand anand.shashwat at gmail.com
Fri Nov 6 22:52:06 CET 2009


Also you can try doing it using strings and this naive method:

>>> s = "aAabbnDeF"
>>> for i in range(1, len(s) - 1):
...     if s[i] in string.ascii_uppercase and s[i - 1] and s[i + 1] in
string.ascii_lowercase:
...         print "".join([s[i - 1], s[i], s[i + 1]])
...
aAa
nDe

It simple look for all capital letters and verify whether it adjacent
letters are small and print it.

On Sat, Nov 7, 2009 at 2:28 AM, Modulok <modulok at gmail.com> wrote:

> See the 're' module in the standard library. To quote the docs:
>
> "This module ('re') provides regular expression matching operations
> similar to those found in Perl. Both patterns and strings to be
> searched can be Unicode strings as well as 8-bit strings."
>
> You can find more information here: http://docs.python.org/library/re.html
> -Modulok-
>
> On 11/6/09, Ajith Gopinath <qbits143 at gmail.com> wrote:
> > Hi,
> >
> > How to find out all the occuerence of a particular pattern like  in a
> long
> > text where a capital letter in between two small letters ('aBa','dAd'
> etc..)
> > || a j i t ||
> >
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091107/cff4db35/attachment.htm>


More information about the Tutor mailing list