PHP Regular Expression

mohamedismail's picture

They have: 10 posts

Joined: Oct 2013

How can we extract string “abc.com” from a string “mailto:[email protected]?subject=Feedback” using regular expression of PHP?

He has: 698 posts

Joined: Jul 2005

It's really not possible to define a regular expression to extract a string without knowing the pattern that you are looking for. For example, in this case you don't need a regular expression. Just look for the string between "@" and "?". However, there must be more extreme cases that are possible if this doesn't work for you. So, you need to specify moreso what the pattern is you know will exist and what portion you want to get back. This can either be a literal pattern, like "mailto:{word}@{string I want}?{more}", or you could at least start with more examples of the type of strings you want to extract a component from, like:

mailto:[email protected]?subject=Feedback
mailto:[email protected]?word=AnotherThing
mailto:[email protected]

If you can provide more information, we can get closer to the regular expression that works for you.

Kurtis

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.