How to find the following pattern in my Char variable in the workspace?
1 view (last 30 days)
Show older comments
Dear All,
I am reading a webpage through data = webread(url); which giving me a Char variable in the workspace called data.
I want ot get all "Strings" inside that char variable that start and end with "SomeText I dont Care":{"raw": SomeSTuff I dont Care }
E.g.: "costOfRevenue":{"raw":4751000000,"fmt":"4,75B","longFmt":"4.751.000.000"},"totalOtherIncomeExpenseNet":{"raw":-213000000,"fmt":"-213M","longFmt":"-213.000.000"}, and so on.............
How can i do this in Matlab?
As you can see it is a webpage so it containes other stuff that i dont care about
Best Regards
7 Comments
Bob Thompson
on 2 Mar 2021
Have you tried using regexp? I would imagine that would allow you to parse out exactly what you want from the website. Something like the following:
raw = regexp(Data,'("costOfRevenue":{"raw".*})','tokens');
I don't expect that to work perfectly the first attempt, I haven't tested it, but it should get you going somewhere.
Accepted Answer
Stephen23
on 4 Mar 2021
Edited: Stephen23
on 4 Mar 2021
Assuming no nested curly braces:
str = '"costOfRevenue":{"raw":4751000000,"fmt":"4,75B","longFmt":"4.751.000.000"},"totalOtherIncomeExpenseNet":{"raw":-213000000,"fmt":"-213M","longFmt":"-213.000.000"}, and so on.............';
rgx = '"\w+":\{"raw":[^}]+\}';
out = regexp(str,rgx,'match');
out{:}
More Answers (0)
See Also
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!