How to insert in a string @ a index

David wizzardx at gmail.com
Sat Sep 8 18:02:44 EDT 2007


On 9/8/07, Zentrader <zentraders at gmail.com> wrote:
> Same solution as above, but if you just want "Hello" and to not
> include words containing "Hello", i.e. "Helloing" or "Unhello", then
> you want to include a leading and/or trailing space.

You can also use the re (regular expression) module to search for
"hello" and make sure it's a complete word. You would use re to search
for something like "\bhello\b". "\b" being regex for an empty string
that only occurs at the start or beginning of a word.

More information on python regexes here: http://www.amk.ca/python/howto/regex/

Here is an example from that page:

>>> p = re.compile(r'\bclass\b')
>>> print p.search('no class at all')
<re.MatchObject instance at 80c8f28>
>>> print p.search('the declassified algorithm')
None
>>> print p.search('one subclass is')
None



More information about the Python-list mailing list