Jump to content

StringRegExp Help


Recommended Posts

Hi there to every one ...

I need a little help with this string :

'T065066\USERNAME4 T065067\USERNAME3 T065068\USERNAME2 T900160\USERNAME1'

How can I extract the T0 or T9 Strings ? I'm rely lost here..

Here is my code :

;Option 1, using offset
$nOffset = 1
While 1
    $x = 'T065066\USERNAME4 T065067\USERNAME3 T065068\USERNAME2 T900160\USERNAME1'
        $array = StringRegExp($x, '(tT){1}(0-9)+', 1, $nOffset)
    
    If @error = 0 Then
        $nOffset = @extended
    Else
        ExitLoop
    EndIf
    for $i = 0 to UBound($array) - 1
        msgbox(0, "RegExp Test with Option 1 - " & $i, $array[$i])
    Next
WEnd
Link to comment
Share on other sites

This is my version:

#include <Array.au3>
;Option 1, using offset
$nOffset = 1
;~ While 1
    $x = 'T065066\USERNAME4 T065067\USERNAME3 T065068\USERNAME2 T900160\USERNAME1'
    $array = StringRegExp($x, '(T0[\d]+|T9[\d]+)\\', 3, $nOffset)

    If @error = 0 Then
    $nOffset = @extended
    Else
    ExitLoop
    EndIf
    _ArrayDisplay($array)
;~ WEnd

BR,

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

This is my version:

#include <Array.au3>
;Option 1, using offset
$nOffset = 1
;~ While 1
    $x = 'T065066\USERNAME4 T065067\USERNAME3 T065068\USERNAME2 T900160\USERNAME1'
    $array = StringRegExp($x, '(T0[\d]+|T9[\d]+)\\', 3, $nOffset)

    If @error = 0 Then
    $nOffset = @extended
    Else
    ExitLoop
    EndIf
    _ArrayDisplay($array)
;~ WEnd

BR,

UEZ

Nice but if there is a small T (t) it will not take it :mellow:

But this one will work = '(?i)(T0[\d]+|T9[\d]+)\\'

Edited by BoogY
Link to comment
Share on other sites

#include <Array.au3>

$nOffset = 1
$x = 'T065066\USERNAME4 T065067\USERNAME3 T065068\USERNAME2 T900160\USERNAME1'
$array = StringRegExp($x, '(?i)(T0[\d]+|T9[\d]+)\\', 3, $nOffset)

If @error = 0 Then
    $nOffset = @extended
Else
    Exit
EndIf
_ArrayDisplay($array)

Too slow... He got to the flag first :mellow:

Edited by Mat
Link to comment
Share on other sites

"(?i)(t[09]\d+)"

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

To get all of the t######### combinations in an array

I also made a typo in the one I posted and the editor is screwing me around to day. It should be

"(?i)(t[09]\d+)"

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thanks I saw the typing error no problem...

It works :mellow:

If you need to test SREs, look in my signature for the PCRE Toolkit.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Ok I have a problem ..

This one works great "(?i)(t[09]\d+" but if I put this strig for example (T065066\USERNAME4 T065067\USERNAME3 T065068\USERNAME2 t900160\USERNAME1 t065066\USERNAME4) It gives me back juste 4 items ??!!! why not all of them ?? the first one is not geting back to me !!!!

Link to comment
Share on other sites

#include <Array.au3>
$x = 'T065066\USERNAME4 T065067\USERNAME3 T065068\USERNAME2 T900160\USERNAME1 T065068\USERNAME2 T065068\USERNAME2 T065068\USERNAME2'
$array1 = StringSplit($x, ' ', 2)
Local $array2[UBound($array1)][2]
For $i = 0 To UBound($array1) -1
    $atemp = StringSplit($array1[$i],"\",2)
    $array2[$i][0] = $atemp[0]
    $array2[$i][1] = $atemp[1]
Next
_ArrayDisplay($array2)

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

Don't forget AutoIt array are zero-based. The output is good:

#include <Array.au3>
Local $x = 'T065066\USERNAME4 T065067\USERNAME3 t065068\USERNAME2 T900160\USERNAME1'
Local $array = StringRegExp($x, '(?i)(T[09]\d+)\\([^\s]+)', 3)
_ArrayDisplay($array)
Local $array2[UBound($array) / 2][2]
For $i = 0 To (UBound($array) / 2) - 1
    $array2[$i][0] = $array[2 * $i]
    $array2[$i][1] = $array[2 * $i + 1]
Next
_ArrayDisplay($array2)

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

Testing it with the toolkit would have shown you what was happening. 0 based array

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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