Parsing everything between quotation using regular expression

18 vues (au cours des 30 derniers jours)
KnowledgeSeeker
KnowledgeSeeker le 7 Fév 2014
Commenté : Walter Roberson le 21 Mar 2019
I m working on a code that parse whatever occur between the quations as shown in my example below
raw="square format" tag_id=
I want parse only between the quotations (highlighted in bold) "whateverhere even space or dots" parse me
your help is highly appreciated
  2 commentaires
per isakson
per isakson le 7 Fév 2014
  • What has tag_id= to do with the question?
  • raw="square format" tag_id= is that a sample string of text, out of which you want to extract square format?
Walter Roberson
Walter Roberson le 7 Fév 2014
You say "whateverhere even spaces or dots". Does that include the possibility of double-quotes ?

Connectez-vous pour commenter.

Réponse acceptée

Ken Atwell
Ken Atwell le 7 Fév 2014
I think you want:
raw='"square format" tag_id='
regexp(raw, '"(.*?)"', 'tokens')
That gives you a cell array of all text found within double quotes, and nothing else. KEN
  5 commentaires
Guillaume
Guillaume le 21 Mar 2019
sst, please start a fresh question rather than commenting on a 5 year old answer.
Walter Roberson
Walter Roberson le 21 Mar 2019
regexp(raw, '"(.*?)(?<!\\)"', 'tokens')
You might want to add the 'once' option if you only expect one occurance.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by