kurbsdude Posted November 3, 2009 Share Posted November 3, 2009 ok i have an expression that could look like these id:1&user:100&age:23 or, (without the & before user) user:100&age:23 or, 1252user:100&age:23 how do i extract 'user:100' from the above expressions? thanks Link to comment https://forums.phpfreaks.com/topic/180122-php-regex-help/ Share on other sites More sharing options...
salathe Posted November 3, 2009 Share Posted November 3, 2009 $subject = "1252user:100&age:23"; preg_match('/user:\d+/', $subject, $match); echo $match[0]; Link to comment https://forums.phpfreaks.com/topic/180122-php-regex-help/#findComment-950221 Share on other sites More sharing options...
kurbsdude Posted November 3, 2009 Author Share Posted November 3, 2009 thanks for the reply but i missed one thing when the expression is user:100&age:23 or 1252user:100&age:23 i want to get user:100 but when the expression is id:1&user:100&age:23 i want to get &user:100 thanks Link to comment https://forums.phpfreaks.com/topic/180122-php-regex-help/#findComment-950337 Share on other sites More sharing options...
cags Posted November 3, 2009 Share Posted November 3, 2009 That's easily fixed. $subject = "1252user:100&age:23"; preg_match('/&?user:\d+/', $subject, $match); echo $match[0]; Link to comment https://forums.phpfreaks.com/topic/180122-php-regex-help/#findComment-950339 Share on other sites More sharing options...
kurbsdude Posted November 6, 2009 Author Share Posted November 6, 2009 That's easily fixed. $subject = "1252user:100&age:23"; preg_match('/&?user:\d+/', $subject, $match); echo $match[0]; thanks a lot btw how do i mark this thread as "solved"? Link to comment https://forums.phpfreaks.com/topic/180122-php-regex-help/#findComment-952590 Share on other sites More sharing options...
nrg_alpha Posted November 6, 2009 Share Posted November 6, 2009 btw how do i mark this thread as "solved"? This is how. Link to comment https://forums.phpfreaks.com/topic/180122-php-regex-help/#findComment-952601 Share on other sites More sharing options...
cags Posted November 6, 2009 Share Posted November 6, 2009 But I don't have a button that glows red.... Link to comment https://forums.phpfreaks.com/topic/180122-php-regex-help/#findComment-952622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.