jeudi 26 mars 2015

Python -- Search Subsrtring Full Word(s)

I want to find the number of times a substring occurred in a string. I was doing this



termCount = content.count(term)


But if i search like "Ford" it returned result set like



"Ford Motors" Result: 1 Correct
"cannot afford Ford" Result: 2 Incorrect
"ford is good" Result: 1 Correct


The search term can have multiple terms like "Ford Motors" or "Ford Auto". For example if i search "Ford Motor"



"Ford Motors" Result: 1 Correct
"cannot afford Ford Motor" Result: 1 Correct
"Ford Motorway" Result: 1 InCorrect


What i want is to search them case insensitive and as a whole. Mean if I search a substring it should be contained as a whole as a word or a phrase (In case of multiple terms) not part of the word. And also I need the count of the terms. How do I achieve it. Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire