Jump to content
Sign in to follow this  
JohnOne

[solved]StrRegExp woes.

Recommended Posts

JohnOne

This is my first venture into trying to figure out a simple pattern,

so scoffing and mockery are welcome if accompanied by any error pointers in my pattern.

My string has some whitespace and other characters possibly including line feeds and/or carraige returns

My aim is to strip everything except digits 0-9 and return the result

When the following code is ran with $sVar it seems to work ok "1234"

but using $sVar2 it only returns "1"

#include <Array.au3>

Local $sVar = "1234"
Local $sVar2 = "1 234"

$rtn = StringRegExp($sVar, "(?x)(\d)*",2)

If @error Then
    MsgBox(0, "ERROR", @error & @CRLF & @extended)
Else
    _ArrayDisplay($rtn)
    MsgBox(0,"Return" $rtn[0])
EndIf
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
SmOke_N

Easier to strip all non digit characters.

$s_ret = StringRegExpReplace($s_str, "\D", "")


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×

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.