n1concepts Posted September 1, 2013 Share Posted September 1, 2013 Hi, I've always struggled w/RegX and need some guidance on how best to parse an xml file that will contain a series of (four) numbers between 1 thru 99 for each column. Note: some of the entries will contain spaces while other will not - see (below) examples: <body> <p>There may be several lines of text prior to the row of numbers we need to capture is presented in later sentences/paragraphs</p> <p>Here is 1st example of numbers we need to capture: 1 - 41 - 16 - 99</p> <p>In this 2nd example, the file may send the numbers: 1-41-16-99</p> <p>Could be alot more text to follow after that set of numbers but will only be one set of the numbers in the file (never multiple). </body> So I got to figure out an expression/function that will: 1. exclude all the other content and just grab (to later echo in script or save to MySQL db) as such: 1-41-16-99 Quote Link to comment https://forums.phpfreaks.com/topic/281756-finding-a-specific-pattern-of-numbers-in-body-content/ Share on other sites More sharing options...
n1concepts Posted September 1, 2013 Author Share Posted September 1, 2013 BTW: I've broke down and reviewing http://www.regular-expressions.info/tutorial.html again to figure it out but any suggestions surely appreciated.... Quote Link to comment https://forums.phpfreaks.com/topic/281756-finding-a-specific-pattern-of-numbers-in-body-content/#findComment-1447683 Share on other sites More sharing options...
Solution .josh Posted September 1, 2013 Solution Share Posted September 1, 2013 preg_match('~[0-9]+\s*-\s*[0-9]+\s*-\s*[0-9]+\s*-\s*[0-9]+~',$content,$match); Quote Link to comment https://forums.phpfreaks.com/topic/281756-finding-a-specific-pattern-of-numbers-in-body-content/#findComment-1447686 Share on other sites More sharing options...
n1concepts Posted September 1, 2013 Author Share Posted September 1, 2013 I won't even ask how you came up with this expression so fast.... I'll just say, 'Thanks!' - much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/281756-finding-a-specific-pattern-of-numbers-in-body-content/#findComment-1447687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.