Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
A simple regexp question

Subject: A simple regexp question

From: matt dash

Date: 29 Jan, 2013 22:34:09

Message: 1 of 3

Hello all,

I have a conceptually simple problem... I have a text file that i've read in as one long string. At various places in this string is the pattern cx="<a number>". The numbers are integers but may contain any number of digits. I'm trying to extract all such numbers from the string. Can this be done easily with regexp? I suspect it has a very simple solution, but i can never quite figure out regexp.

Thanks,
Matt

Subject: A simple regexp question

From: Bruno Luong

Date: 29 Jan, 2013 22:49:09

Message: 2 of 3

>> s = '000 first cx=123, second cx=12345,...'

s =

000 first cx=123, second cx=12345,...


>> c = regexp(s,'cx=(\d*)','tokens')

c =

    {1x1 cell} {1x1 cell}


>> cellfun(@str2double, c)

ans =

         123 12345

% Bruno

Subject: A simple regexp question

From: matt dash

Date: 29 Jan, 2013 23:18:12

Message: 3 of 3

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ke9jl5$m9j$1@newscl01ah.mathworks.com>...
> >> s = '000 first cx=123, second cx=12345,...'
>
> s =
>
> 000 first cx=123, second cx=12345,...
>
>
> >> c = regexp(s,'cx=(\d*)','tokens')
>
> c =
>
> {1x1 cell} {1x1 cell}
>
>
> >> cellfun(@str2double, c)
>
> ans =
>
> 123 12345
>
> % Bruno

Great, thanks!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us