フィルターのクリア

Regexp: Take the expression with text only

1 回表示 (過去 30 日間)
Vincent
Vincent 2016 年 3 月 3 日
回答済み: Guillaume 2016 年 3 月 3 日
Hi,
I am new with regexp... I have one string
Test='"Name": "Vincent_1213","Name": "Vincent"';
And I would like to take the expression "Name": "Vincent" and NOT "Name": "Vincent_1213". I am using
regexp(Test,'"Name": "(.*?)"','match')
but it finds naturally both expressions. I cannot enter "Vincent" or "Vincent_1213" in the search because this info will change all the time. "Name": "" is the only consistent expression that I will get all the time.
Does someone have any idea on how to use regexp in order to take the expression with only text ?
  2 件のコメント
Guillaume
Guillaume 2016 年 3 月 3 日
What is the reason for rejecting "Vincent_1213"? The fact that it's got numbers? The fact that it's got an underline? Some other reason?
Vincent
Vincent 2016 年 3 月 3 日
It can have space and "-" For instance it can be "Carl-David Dupont" and "Carl-David Dupont_2549". In this case and all other cases I want the first expression and not the second one. Cause of rejection: number and underline (both of them will be systematically located at the same place all the time)

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2016 年 3 月 3 日
So basically, for the name you want to match any character that is not a number, or underscore. You could also add that you do not want to match the quote '"' to avoid the non-greedy operator. All of this is easily specified as a negated character class: [^0-9_"], so:
regexp(Test, '"Name": "[^0-9_"]+"', 'match')
%and if you just want the name itself:
regexp(Test, '(?<="Name": ")[^0-9_"]+(?=")', 'match')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by