dsaba Posted March 1, 2008 Share Posted March 1, 2008 I'm trying to match php like function declarations that have 1 argument in them. The problem is matching proper digits with an if/else expression. The root of the problem is here: (??=\.)[\d]+|\d+\.?\d*) Full pattern: (?<![\w_])[a-z][\w_]*\s*\(\s*(((?<![\$\w_])[\$a-z][\w_]*(?![\$\w_]|\s*\()\s*=\s*)?((?<![\$\w_])[\$a-z][\w_]*(?![\$\w_]|\s*\()|"[^"]*"|(??=\.)[\d]+|\d+\.?\d*)))\s*\) Haystack: thisFunc("hello"); //yes thisFunc($var = "hello"); //yes name(var = var); //yes name(var = 2.3); //yes name(var = 2.3.); //no name(.5) //yes [here is the problem it doesn't match here] name(var = .58) //yes [here is problem, it doesn't match here] name(var = .5. //no So how can I match these numbers? either .23 or 0.23, it doesn't match .23 types Thanks for looking. Link to comment https://forums.phpfreaks.com/topic/93886-ifelse-regex-expression-not-working-correctly-in-matching-numbers/ Share on other sites More sharing options...
dsaba Posted March 1, 2008 Author Share Posted March 1, 2008 changed it to this and works as expected: (\d+|\.\d+|\d+\.\d*) if you've got a better idea, let me know Link to comment https://forums.phpfreaks.com/topic/93886-ifelse-regex-expression-not-working-correctly-in-matching-numbers/#findComment-481066 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.