Skip to content

Instantly share code, notes, and snippets.

@chartjes
Created February 8, 2012 22:10
Show Gist options
  • Save chartjes/1774431 to your computer and use it in GitHub Desktop.
Save chartjes/1774431 to your computer and use it in GitHub Desktop.
I need help extracting some info using a regex in PHP.
I have a string is like this
[email protected]
-> foo can change but is always lowercase alpha, variable length
-> tmp is ALWAYS tmp
-> uniqid is always lowercase alpha plus 0 to 9, output from uniqid() function
-> moontoast.com is ALWAYS moontoast.com
I need to extract the uniqid value from that string, using PHP.
Please help as my regex foo is weak
[email protected]
@dhrrgn
Copy link

dhrrgn commented Feb 8, 2012

@stuartherbert @maxmanders @robertbasic @JCook21 All of yours have various issues: must escape the 'dot' in "moontoast.com" or it would match anything like "moontoastecom" (the dot represents any character), one doesn't take the 'tmp' into account, and a few accept anything in the uniqid portion.

EDIT: Same general things apply to all the ones here.

@JCook21
Copy link

JCook21 commented Feb 8, 2012

@dhorrigan Good point. Updated to escape the '.'.

@robertbasic
Copy link

gah! github ate my stars in the regex :(

@tnorthcutt
Copy link

A humble vote for the solution proposed by @shama. Seems like foo, tmp, and anything after the @ are irrelevant.

@shama
Copy link

shama commented Feb 8, 2012

@robertbasic use backticks ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment