Regular expression for a Python Dict.

조회 수: 10 (최근 30일)
Ajpaezm
Ajpaezm 2018년 11월 10일
댓글: Walter Roberson 2018년 11월 10일
Hey guys,
I have a python dict that I have turned into a string using char(values()) command, the outcome after that is the following:
exp = 'dict_values([8590932455, 8590922136, 8590923186, 21640072856, 8590965080])'
I've been trying to get a regular expression that would allow me to acquire all the long numbers (8590932455, 8590922136, ..., 8590937754).
I tried something like this:
test = regexp(exp, '(\d+)', 'match');
And this works... but only when the string has only numbers. What if I had something like a mixture of letters and numbers (A1B2C3), or only letters (AJASNJASBAVENQI)? How can I make my regular expression work for all those 3 cases simultaneously?
Thanks in advance.
  댓글 수: 2
Ajpaezm
Ajpaezm 2018년 11월 10일
THis gets me pretty close to what I'm looking for, if not for those "dict" and "values" string (which I can comfortably get rid of using strrep).
cellStr = regexp(cellStr,'[A-Za-z0-9]+','match');
Walter Roberson
Walter Roberson 2018년 11월 10일
regexp with 'split' on comma
However if dictionary entries include letters then perhaps they are quoted strings in which case you need to be more careful especially if they could happen to contain comma or quote marks

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by