Jump to content
Sign in to follow this  
KenNichols

I am having trouble understanding StringRegExp.

Recommended Posts

KenNichols

I am having trouble understanding StringRegExp.

If $Result = ###.# then it works fine but if it = #,### then it comes up #,# and not #,###.

I hope this makes sense to someone!

$data = StringRegExp($Result, "([0-9]*.[0-9])",1)


[topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!

Share this post


Link to post
Share on other sites
PsaltyDS

I am having trouble understanding StringRegExp.

If $Result = ###.# then it works fine but if it = #,### then it comes up #,# and not #,###.

I hope this makes sense to someone!

$data = StringRegExp($Result, "([0-9]*.[0-9])",1)

The "+" following a matching unit indicates "one or more", so:
#include <Array.au3>

$sInput = "1.1" & @CRLF & _
    "2.22" & @CRLF & _
    "3.333" & @CRLF & _
    "4.4444" & @CRLF & _
    "1,1" & @CRLF & _
    "2,22" & @CRLF & _
    "3,333" & @CRLF & _
    "4,4444"
    
$avRET = StringRegExp($sInput, "([0-9]+.[0-9]+)", 3) 
_ArrayDisplay($avRET, "$avRET")

^_^


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
KenNichols

The "+" following a matching unit indicates "one or more", so:

#include <Array.au3>

$sInput = "1.1" & @CRLF & _
    "2.22" & @CRLF & _
    "3.333" & @CRLF & _
    "4.4444" & @CRLF & _
    "1,1" & @CRLF & _
    "2,22" & @CRLF & _
    "3,333" & @CRLF & _
    "4,4444"
    
$avRET = StringRegExp($sInput, "([0-9]+.[0-9]+)", 3) 
_ArrayDisplay($avRET, "$avRET")

^_^

WOW! I thought I tried the +! Guess not, but it works great now thanks!

I have one question though why the Flag of 3 and not 1?


[topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner!

Share this post


Link to post
Share on other sites
Authenticity

3 Indicates to keep searching the entire string so it'll try to match this pattern until it reaches the end of the string. By the way, if you want to match numbers like .33, .129 which are perfectly valid use this pattern:

((?:[0-9]+)?.[0-9]+)

Edit: Moi mistake ;], you need to escape the '.' metacharacter to match the dot character and not what it's govern. This is the correct pattern:

((?:\d+)?\.\d+)

\d = [0-9], shorthand for all digits.

Edit2:

;]

PsaltyDS was right, matching a decimal, and matching a thousands separated number are two distinct things... So to solve it in one shot you should use his way, i.e, (\d+.\d+) or (\d+[.,]\d+)

Edited by Authenticity

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×