MATLAB: Find the string into an special bracket

MATLABregexpregression

Hello All, I have a string.
Ex: str = 'abc = "xyz";'
I want to use regexp command to find out "xyz" in below string.
my patern :
pat = '^=.;$'
with meaning (as my understanding)
_^= : beginning with =
. : get all thing between
;$ : ending with ;_
and run with
tk = regexp(str, pat) –> tk = [] in result
what wrong with my commands?
Thanks!

Best Answer

  • ^ is the start of the string, not of the searched pattern.
  • Equivalently $ is the end of the string, not the pattern, too.
What about:
regexp(str, '"(.*?)"', 'match')
or
regexp(str, '"([^"]*)"', 'match')