954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Finding isolated instances of characters in a string

In this string "13 12", I like to find if there is an occurrence of '3', but I am not interested in char '3' which is part of "13". In other word I am looking for number 3 not 13.
By using the following code in python I always get a match,

match = re.match('3','13 12')


Any help regarding how to find isolated occurrences of characters or sequence of characters will be appreciated.

hamidvosugh
Newbie Poster
11 posts since Jul 2008
Reputation Points: 10
Solved Threads: 2
 
>>> print('3' in  '13 12'.split())
False
>>> print('3' in  '13 12 333 453 2 3 433'.split())
True
pyTony
pyMod
Moderator
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
 

There is also re.search(r'\b3\b', '13 12 333 453 2 3 433') but it will match -3 too.

Gribouillis
Posting Maven
Moderator
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: