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.

Recommended Answers

>>> print('3' in  '13 12'.split())
False
>>> print('3' in  '13 12 333 453 2 3 433'.split())
True
Jump to Post

All 2 Replies

>>> print('3' in  '13 12'.split())
False
>>> print('3' in  '13 12 333 453 2 3 433'.split())
True

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.