How to extract data from a srting?

1 view (last 30 days)
Hi,
*I have this data as a single string *
Physical Location (City):Virginia
Manager of this associate:Donna Harding
Start Date:1-1-99
ID Type:Logon for SUPERVALU associate
For Transfer Requests From Dept:
Transfer Date:
Previous UserID:
Departure Date:
Middle Name:
I want to extract the name of the manager from the
Manager of this associate:Donna Harding
I mean I want data in the above string after : to be stored in other variable.
Could anyone help me in doing this?
Thank You
  3 Comments
Jan
Jan on 31 Jan 2013
This description as a text does not enlighten me. What is "the Matlab input"? Each cell has the data? Do you mean a cell string? With one line per cell element, or with one string and line breaks?
Again I suggest to post Matlab code due to the unbeatable clarity.

Sign in to comment.

Accepted Answer

Cedric Wannaz
Cedric Wannaz on 31 Jan 2013
Edited: Cedric Wannaz on 1 Feb 2013
Solution with a regexp:
regexp(s, '(?<=associate:).*(?=Start)', 'match')
where s contains your string.
EDIT: the following would work as well..
regexp(s, '(?<=[^)]:).*(?=Start Date)', 'match')
..does anybody have a simpler pattern proposal?
  1 Comment
Vinay kumar Reddy
Vinay kumar Reddy on 1 Feb 2013
Thanks!!! Cedric
That works great!!!

Sign in to comment.

More Answers (1)

Matt J
Matt J on 31 Jan 2013
Edited: Matt J on 31 Jan 2013
b='Manager of this associate';
e='Start Date';
ib=strfind(str,b);
ie=strfind(str,e);
str(ib+length(b):ie-1)

Community Treasure Hunt

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

Start Hunting!