Jump to content

if/else regex expression not working correctly in matching numbers


dsaba

Recommended Posts

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.