jnvnsn Posted July 20, 2011 Share Posted July 20, 2011 Is there anyway i can print the rest of this string if i already match the email? Hilton Newark Penn Station Fl 1, 1 Gateway Ctr, Newark, NJ (973) 622-5000 hilton@yahoo.com Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 20, 2011 Share Posted July 20, 2011 do you want the phone number too or just the address? Quote Link to comment Share on other sites More sharing options...
jnvnsn Posted July 20, 2011 Author Share Posted July 20, 2011 both the address and the phone number AyKay47. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 20, 2011 Share Posted July 20, 2011 $subject = "Hilton Newark Penn Station Fl 1, 1 Gateway Ctr, Newark, NJ (973) 622-5000 hilton@yahoo.com"; $pattern = '~^([\w\d\s,]+)(\(\d{3}\s*\d{3}-\d{4}\))~'; preg_match($pattern, $subject, $matches); foreach($matches as $match){ print "$match matches the pattern"; } Quote Link to comment Share on other sites More sharing options...
jnvnsn Posted July 20, 2011 Author Share Posted July 20, 2011 It doesn't return anything.hmm Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 20, 2011 Share Posted July 20, 2011 messed up the pattern.. $pattern = '~^([\w\d\s,]+)(\(\d{3}\)\s*\d{3}-\d{4})~'; Quote Link to comment Share on other sites More sharing options...
jnvnsn Posted July 20, 2011 Author Share Posted July 20, 2011 $pattern = '~^([\w\d\s,]+)(\(\d{3}\)\s*\d{3}-\d{4})~'; can you disect this one for me? i'm not good at regex. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 20, 2011 Share Posted July 20, 2011 well sure, what exactly do you want to know about it? Quote Link to comment Share on other sites More sharing options...
xyph Posted July 21, 2011 Share Posted July 21, 2011 ^([\w\d\s,]+)(\(\d{3}\)\s*\d{3}-\d{4}) Options: ^ and $ match at line breaks; free-spacing Assert position at the beginning of a line (at beginning of the string or after a line break character) «^» Match the regular expression below and capture its match into backreference number 1 «([\w\d\s,]+)» Match a single character present in the list below «[\w\d\s,]+» Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+» A word character (letters, digits, and underscores) «\w» A single digit 0..9 «\d» A whitespace character (spaces, tabs, and line breaks) «\s» The character “,” «,» Match the regular expression below and capture its match into backreference number 2 «(\(\d{3}\)\s*\d{3}-\d{4})» Match the character “(” literally «\(» Match a single digit 0..9 «\d{3}» Exactly 3 times «{3}» Match the character “)” literally «\)» Match a single character that is a “whitespace character” (spaces, tabs, and line breaks) «\s*» Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*» Match a single digit 0..9 «\d{3}» Exactly 3 times «{3}» Match the character “-” literally «-» Match a single digit 0..9 «\d{4}» Exactly 4 times «{4}» Created with RegexBuddy Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 21, 2011 Share Posted July 21, 2011 never heard of regex buddy, looks like it could be useful..if it's free Quote Link to comment Share on other sites More sharing options...
xyph Posted July 21, 2011 Share Posted July 21, 2011 Not free. Extremely useful. For an amateur coder? Perhaps not, but if you're a professional, the $40 pays for itself VERY quickly. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 21, 2011 Share Posted July 21, 2011 Not free. Extremely useful. For an amateur coder? Perhaps not, but if you're a professional, the $40 pays for itself VERY quickly. you recommend it i'm guessing? I use regex alot so anything that can cut down on my brain power time is a good thing..lol...what is the functionality, what all can you do with it? Quote Link to comment Share on other sites More sharing options...
xyph Posted July 21, 2011 Share Posted July 21, 2011 There used to be a trial. To be honest, I used a cracked version when I was first learning, but purchased not long after. Here's a page with demos of what it can do http://www.regexbuddy.com/demo.html I'm a HUGE supporter of really trying before you buy, and you can easily find a somewhat recent version in the usual popular places to try. I do NOT support piracy, though - if you do that and decide you don't want to pay, please uninstall. I mostly use it for it's debugging features. Helps you make faster expressions, and see where the engine is backtracking. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 22, 2011 Share Posted July 22, 2011 There used to be a trial. To be honest, I used a cracked version when I was first learning, but purchased not long after. Here's a page with demos of what it can do http://www.regexbuddy.com/demo.html I'm a HUGE supporter of really trying before you buy, and you can easily find a somewhat recent version in the usual popular places to try. I do NOT support piracy, though - if you do that and decide you don't want to pay, please uninstall. I mostly use it for it's debugging features. Helps you make faster expressions, and see where the engine is backtracking. cool, thanks man Quote Link to comment 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.