How do i use regular expressions effectively for parsing my text?
Show older comments
Hello,
I am currently using regular expressions for parsing my text. The pattern is:
pattern = 'red(dy|dish)?'
regexp(text,pattern,'match')
the answer is reddy, reddish, red. However the pattern recognizes red in words like predominantly , predetermined etc. I do not want this to happen. I want the regular expressions to only return words which describe color red (example red, reddy, reddish). How do i change my pattern or regular expression accordingly? Any help in this regard would be highly appreciated.
Thanks, Phani
Accepted Answer
More Answers (3)
Azzi Abdelmalek
on 19 Jun 2013
Edited: Azzi Abdelmalek
on 19 Jun 2013
text='red redy predominant red ade redish red vrd redishh'
pattern='(?<=\s)red(y|ish)?(?!\S)'
regexp([' ' text],pattern,'match')
Phanichin
on 20 Jun 2013
0 votes
2 Comments
Azzi Abdelmalek
on 20 Jun 2013
They are different solutions and giving different results
Phanichin
on 24 Jun 2013
Phanichin
on 24 Jun 2013
0 votes
1 Comment
Andrei Bobrov
on 24 Jun 2013
Please see ADD part in my answer.
Categories
Find more on Install Products in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!