Reputation: 10117
Im handling various email addresses that come in the following forms
John Doe <[email protected]>
[email protected]
How could i use regex, to find the @ symbol, and then return the integer's behind it (until it doesnt find anymore, or runs into a non number, < or space for example.)
Upvotes: 0
Views: 84
Reputation: 4755
You could try something like...
preg_match("#^[\D]+\<([\d]+)#", "John Doe <[email protected]>", $matches);
Upvotes: 0
Reputation: 59973
/^\D*(\d*)@/
Will match any number of non-digits, any number of digits, followed by an @.
The capturing group will contain the digits.
Upvotes: 2
Reputation: 143114
Just search for this regex:
(\d*)@
And then look at the first capture group.
Upvotes: 1