Extracting string...
Hi all,
I'm currently in the process of writing a script to parse an email that I get from my message board so that rather than having to click through emails to manually approve members, I can do it via a web page.
As part of this, I need to extract the username from the email. The username is always contained within quote marks (i.e. "username")
Does anyone know if there is a php function that will match a regular expression and give you the matched text as a variable? I thought preg_match would do the job but from what I can tell that just returns a count of how many times it matches?
Also, does anyone know what the regular expression would be?
I've tried: \"+[a-zA-Z0-9]\" (one or more alpha numeric characters) but that didnt seem to work.
What I guess I really need is a quote mark followed by up to 50 of anything then another quote mark... any ideas? I hate regex! (but seriously need to learn it!)
Andy
Abhishek Reddy posted this at 00:58 — 13th February 2007.
He has: 3,348 posts
Joined: Jul 2001
It does return only the number of matches, but preg_match() will work. It takes an argument called matches that names a variable in which the function will store an array of successfully matched strings.
This is the bizarre world of PHP, after all.
You've got the + on the wrong side. Try [incode]\"[a-zA-Z0-9]+\"[/incode].
andy206uk posted this at 01:51 — 13th February 2007.
He has: 1,758 posts
Joined: Jul 2002
ah ha! I'll get there with the regex one day!
Thanks mate!
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.