Jump to content

I am having trouble understanding StringRegExp.


Recommended Posts

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
Link to comment
Share on other sites

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!
Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...