how to find a exact word in a string?

Hi I am trying to return the value that matches with a given word in a string...
str = 'talk talking people talk talking talk'
if this is my string and I am trying to return how many times 'talk' shows up in the string, what should I do?
this is my code so far but it also returns 'talking'... is there any other way to fix this?
find = strfind(str, 'talk')

Answers (1)

length(regexp(str, '\<talk\>'))

4 Comments

if I assign a word to a variable and use regexp it does not work...can you help me with this?
str = 'talk talking people talk talking talk'
word1 = 'talk'
word2 = 'talking'
['\<' word1 '\>'] % in expression of sir Walters code
Madhan is correct, ['\<' word1 '\>'] as the pattern
Thanks you, It works perfect

Sign in to comment.

Categories

Tags

Asked:

on 5 Jul 2020

Commented:

on 11 Oct 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!