mrpatg
mrpatg

Reputation: 10117

another regex email post (in php)

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

Answers (3)

Chris Gutierrez
Chris Gutierrez

Reputation: 4755

You could try something like...

preg_match("#^[\D]+\<([\d]+)#", "John Doe <[email protected]>", $matches);

Upvotes: 0

Anon.
Anon.

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

Laurence Gonsalves
Laurence Gonsalves

Reputation: 143114

Just search for this regex:

(\d*)@

And then look at the first capture group.

Upvotes: 1

Related Questions