Regular expressions help with HTML source code
Show older comments
I'm looking to parse through some HTML source code to pull information from the Wall Street Journal. I need to pull the price of the following commodities: the 4 domestic crude oil spot prices, copper, aluminum, cotton, and cocoa
I'm having some trouble with getting regexp to work the way I want it to.
what string expression would you use to pull out the middle (bold) price listed? If the value is n.a., it's okay if it just returns 'n.a.' or its equivalent.
I tried a variety of methods and I couldn't get it to work.
Could someone show an example of the string he or she would use for extracting the price?
Thanks!
Accepted Answer
More Answers (1)
Walter Roberson
on 11 Mar 2013
'^<b>.*?\d+(\.\d+)?<\\b>$'
This should allow for the currency symbol, and for the possibility that the decimal point and following digits are not there. The only real "trick" here is the use of .*? to indicate the minimum expansion of repeated . (i.e., match any one character) where .* by itself is "greedy" and would match as many characters as possible.
1 Comment
Joseph Williams
on 12 Mar 2013
Categories
Find more on Common Operations 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!