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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.