Can someone explain this regexp command?

조회 수: 7 (최근 30일)
Justin Schrout
Justin Schrout 2017년 5월 16일
편집: Stephen23 2017년 5월 17일
I have some code:
expr = '<Placemark>.*?</Placemark>';
objectStrings = regexp(txt,expr,'match');
This works exactly as I would like it to. However, I am not fundamentally understanding what Matlab is doing, specifically when I see the .*? I have pored over the documentation, but I am just not understanding. Would someone please be kind enough to explain what is happening?
  댓글 수: 1
KSSV
KSSV 2017년 5월 17일
What is txt in the input of regexp?

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

답변 (1개)

Stephen23
Stephen23 2017년 5월 17일
편집: Stephen23 2017년 5월 17일
It is quite simple:
<Placemark> % match literal string
.* % match any characters, any number of times
? % makes the previous quantifier lazy (ie *)
</Placemark> % match literal string
The MATLAB documentation explains how regular expressions work:
And we find it explains all of those parts of your regular expression:
  • angle brackets are not special characters, therefore the "placemark" parts are interpreted literally.
  • " expr* 0 or more times consecutively."
  • " exprq? Lazy expression: match as few characters as necessary."

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by