Scan a pattern of characters from a string
Show older comments
Hello everyone, I have a text file from I am required to scan a pattern (string 'SSD' followed by an integer). I am trying to use the 'regexp' command for this operation. For eg. I have used the command 'fgetl' to store a line which contains the pattern I require. Could you help me with this? I want 'ord1' to find the pattern 'SSD1' from 'tline'! Thank you in advance!
tline = ## Step : SSD1
ord1 = regexp(tline,'(?<=SSDd+)','match');
Accepted Answer
More Answers (1)
Image Analyst
on 6 Nov 2015
Here's an alternate way that is less cryptic than regexp():
tline = '## Step : SSD1'
ssdLocation = strfind(tline, 'SSD') % Find index of SSD
% Extract the end of the string and convert it to a number.
ord1 = str2double(tline(ssdLocation+3:end))
1 Comment
Karthik Brs
on 6 Nov 2015
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!