Jump to content

[solved]StrRegExp woes.


JohnOne
 Share

Recommended Posts

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.

Link to comment
Share on other sites

  • Moderators

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.

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