Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-03-2012, 12:42 AM   PM User | #1
mathceleb
Regular Coder

 
Join Date: Mar 2010
Posts: 235
Thanks: 39
Thanked 6 Times in 6 Posts
mathceleb is an unknown quantity at this point
Regex digit plus sign digit

The variable "add_count" is always 1. Here is what I tried:

PHP Code:
$n="6+0+1";
$add_count preg_match_all('/-?\d+(\+)\d+/'$n$match2); 
Also tried this:

PHP Code:
$n="6+0+1";
$add_count preg_match_all('/\b-?\d+(\+)\d+$/'$n$match2); 
It still evaluates to 1 and not 2.
mathceleb is offline   Reply With Quote
Old 11-03-2012, 02:47 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
The first expression matches to 6+0 and then decides that +1 doesn't match.

The second one matches 0+1 and then doesn't have any further content to check.

So on both cases there is only one number+number that can be matched (given that the search for another match starts from the end of the previously matched text).
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Tags
regex

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:35 AM.


Advertisement
Log in to turn off these ads.