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!

 채택된 답변

Jan
Jan 2018년 7월 21일
편집: Jan 2018년 7월 21일

0 개 추천

  • ^ 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')

댓글 수: 2

[MOVED from section for answers] Tan Phan wrote:
Thank for your answer.
I have more question.
What happen if str is not a string I input from command Window.
I save it in file and using fopen/textscan to parse it.
In that file with information : abc = 'xyz';
I changed "xyz" to 'xyz' and I can not parse it with your regexp command ( ' '(.*?)' ' or ' '([^']*)' ') is not available in Matlab with my test.
Jan
Jan 2018년 7월 23일
편집: Jan 2018년 7월 23일
"Is not available"? Remember that you need two quote characters inside a string to represent quote:
str = 'This is one quote: [''] '
Run this in the command window to check it.
Parsing quotes can interfere with e.g. "it's"

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

질문:

2018년 7월 21일

편집:

Jan
2018년 7월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by