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:
regexprep question

Subject: regexprep question

From: sushma sharma

Date: 13 Feb, 2008 16:37:03

Message: 1 of 5

hi,

i have a string

'IND OK 2 P190'

how can i write a regexprep function to get the the element
between the second and third space (i.e., 2) and the first
letter of the word after the third space?

i want the out put to be

'2 P'

thank you!

sushma

Subject: regexprep question

From: Doug Schwarz

Date: 13 Feb, 2008 17:18:29

Message: 2 of 5

In article <fov6bf$qoi$1@fred.mathworks.com>,
 "sushma sharma" <ssharma@ynospamahoo.com> wrote:

> hi,
>
> i have a string
>
> 'IND OK 2 P190'
>
> how can i write a regexprep function to get the the element
> between the second and third space (i.e., 2) and the first
> letter of the word after the third space?
>
> i want the out put to be
>
> '2 P'
>
> thank you!
>
> sushma

Try

  c = regexp('IND OK 2 P190','^.+ .+ (.+ .).*','tokens');
  output = c{1}

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Subject: regexprep question

From: sushma sharma

Date: 13 Feb, 2008 17:21:08

Message: 3 of 5

here's what i have so far...no luck yet

regexprep(Sheet1,'(?<=((\S+\s){2})\S+ + (?:\s)(\S).*', '$1 $2 ')


any help would be appreciated!

sushma

Subject: regexprep question

From: sushma sharma

Date: 13 Feb, 2008 17:44:03

Message: 4 of 5

hi,

i made a mistake in my posting.

my string is in the form

'IND OK 2 P190 ENTER'

how can i write a regexprep function to get the the element
between the second and third space (i.e., 2) and the first
letter of the word after the third space (i.e. P)?

i want the out put to be

'2 P'

Any help would be appreciated!!!

sushma

Subject: regexprep question

From: sushma sharma

Date: 13 Feb, 2008 18:00:06

Message: 5 of 5

ok figured it out.

regexprep(Sheet1,'(^((\S+\s){2})\S+\s + (?:\S).*', '$1 $2 ')

thanks for the help!

sushma

Tags for 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