CaptainC Posted March 28, 2006 Share Posted March 28, 2006 I have an error with this statement:[code]preg_match("[0-9]+\.?[0-9]*", $text_string, $match_array);[/code][!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: preg_match(): Unknown modifier '+' in ...[/quote]I thought it had something to do with the slashed in php strings, but I have not been able to get it right.Any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/6013-preg_match-error/ Share on other sites More sharing options...
shoz Posted March 28, 2006 Share Posted March 28, 2006 You forgot to add delimiters to the regex.[code]preg_match("/[0-9]+\.?[0-9]*/", $text_string, $match_array);[/code]This question is also more appropriate for the PHP-Help forum and will be moved. Always look for the most appropriate forum for your question before posting. Quote Link to comment https://forums.phpfreaks.com/topic/6013-preg_match-error/#findComment-21607 Share on other sites More sharing options...
CaptainC Posted March 28, 2006 Author Share Posted March 28, 2006 Would this regex be the way to go if I wanted to pull out the number value from this example?:<b><i>$456.50</i></b>And have preg_match pull out "456.50" ? Quote Link to comment https://forums.phpfreaks.com/topic/6013-preg_match-error/#findComment-21627 Share on other sites More sharing options...
shoz Posted March 28, 2006 Share Posted March 28, 2006 [quote]Would this regex be the way to go if I wanted to pull out the number value from this example?:<b><i>$456.50</i></b>And have preg_match pull out "456.50" ?[/quote]If the string will only contain one number then it should be fine. The regex will match a number that ends with a "." however, which may not be what you want. You could change it to the following to avoid that.[code]/[0-9]+(.[0-9]+)?/[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6013-preg_match-error/#findComment-21650 Share on other sites More sharing options...
wickning1 Posted March 28, 2006 Share Posted March 28, 2006 You can use this:[code]preg_match('/\d*(\.\d+)?/', $text_string, $match_array);$number = $match_array[0];[/code]That will match '0.1', '3', and '.1'. Quote Link to comment https://forums.phpfreaks.com/topic/6013-preg_match-error/#findComment-21654 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.