Jump to content

StringRegExp Question


Recommended Posts

Lets say I have a string = "eraTESf ER , - 347 DFE,ad"

I want to format to be only letters(lower and upper), take away everything else including the space

So in result, it should be "eraTESfERDFEad"

How can I achieve this using StringRegExp ? or perhaps some better option ?

Thank you for any help

Howie

Link to comment
Share on other sites

Assuming you mean ASCII letters (i.e. english letters) only, try this:

$string = "eraTESf ER , - 347 DFE,ad"

$result = StringRegExpReplace($string, "(?i)[^a-z]", "")

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Thank you Volly. This is very helpful. I had below code.

$string = "eraTESf ER , - 347 DFE,ad"

$formatted = StringRegExp($string, "[a-zA-Z]")

msg(0,"",$formatted)

How come $formatted always result 1 ?

Thanks

Link to comment
Share on other sites

The regexp option you use (third parameter defaults to 0) return a bolean result 0 or 1 meaning no match or match.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Hi,

Thanks for the help. I guess I was in the wrong direction. I had below code which will format string from

"ajvelrjlejrje*&^%$#@!_)(+_-=':'/.,><}{][\|akr2342343" --> "ajvelrjlejrje"

$test = "ajvelrjlejrje*&^%$#@!_)(+_-=':'/.,><}{][\|akr2342343"

$testarray = StringSplit($test,"")
;MsgBox(0,"",$testarray[0])
$formatted =""

for $i = 1 to $testarray[0]
    if StringIsAlpha($testarray[$i]) Then
        $formatted = $formatted & $testarray[$i]
    EndIf
Next
MsgBox(0,"",$formatted)

I am just wondering if there is any better way to achieve this. Thank

Link to comment
Share on other sites

That's indeed overcomplex!

Look again 4 posts above.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

This is working for me:

$test = "ajvelrjlejrje*&^%$z#Z@!_)ABC(+_-=':'/.,><}{][\|akr2342343"

$StrReg = StringRegExpReplace($test, "[\W\d^\_]", "")

$testarray = StringSplit($test,"")
;MsgBox(0,"",$testarray[0])
$formatted =""

for $i = 1 to $testarray[0]
    if StringIsAlpha($testarray[$i]) Then
    $formatted = $formatted & $testarray[$i]
    EndIf
Next
MsgBox(0,"",$formatted & @CRLF & $StrReg)

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Assuming you mean ASCII letters (i.e. english letters) only, try this:

$string = "eraTESf ER , - 347 DFE,ad"

$result = StringRegExpReplace($string, "(?i)[^a-z]", "")

Thank you for your help. This is what I am looking .

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