Jump to content

StringRegExp General Help


Recommended Posts

Hope that this will help you to understand what i want to do, of course is only an example:

$hOpen = FileOpen(@ScriptDir & "\test.txt")
$sRead = FileRead($hOpen)
FileClose($sRead)

$aHTMLRemove = StringRegExpReplace($sRead, "(^[^<]*>|<[^>]*>|<[^>]*$)", "", 0)

$aSplit = StringSplit($aHTMLRemove, @CRLF, 1)

For $i = 1 To $aSplit[0]
    $aRegex = StringRegExp($aSplit[$i], "#(\d+)\s+(.*?)\s+(.*?)\s+(.*)$", 3)

    If Not @error Then
        ConsoleWrite(">>Item number " & $aRegex[0] & "<<" & @CRLF) ;ID
        ConsoleWrite($aRegex[1] & " ") ;Category
        ConsoleWrite($aRegex[2] & " ") ;Quantity
        ConsoleWrite($aRegex[3] & @CRLF & @CRLF) ;Product name
    EndIf
Next
This is the contenent of test.txt:

<html>
<head>Test</test>
<body>
<SOME HTML TAG>
List generated on xxx some random test
#1 Screws 5 Universal_Screws_SEt
#2 Hammer 10 Claw_Hammer
#3 Led 10 Blue_Led
</body>
</html>
Now my question is. Due the HUGE txt that i have, someone have a faster way to do that, maybe a more optimized SRE?

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

#include <Array.au3>

$sRead= _
'<html>' & @CRLF & _
'<head>Test</test>' & @CRLF & _
'<body>' & @CRLF & _
'<SOME HTML TAG>' & @CRLF & _
'List generated on xxx some random test' & @CRLF & _
'#1 Screws 5 Universal_Screws_SEt' & @CRLF & _
'#2 Hammer 10 Claw_Hammer' & @CRLF & _
'#3 Led 10 Blue_Led' & @CRLF & _
'</body>' & @CRLF & _
'</html>'

$timer = TimerInit()
$aRegex = StringRegExp($sRead, "(?m)^#(\d+)\h+(.+?)\h+(.+?)\h+(.+?)\r?$", 3)
$u = UBound($aRegex)
Local $aRegex2D[$u][4]
$j = 0
For $i = 0 To $u-1 Step 4
    $aRegex2D[$j][0] = $aRegex[$i]
    $aRegex2D[$j][1] = $aRegex[$i + 1]
    $aRegex2D[$j][2] = $aRegex[$i + 2]
    $aRegex2D[$j][3] = $aRegex[$i + 3]
    $j += 1
Next
ReDim $aRegex2D[$j][4]
_ArrayDisplay($aRegex2D, 'Time : ' & Round(TimerDiff($timer) / 1000, 2) & ' sec')

Link to comment
Share on other sites

#include <Array.au3>

$sRead= _
'<html>' & @CRLF & _
'<head>Test</test>' & @CRLF & _
'<body>' & @CRLF & _
'<SOME HTML TAG>' & @CRLF & _
'List generated on xxx some random test' & @CRLF & _
'#1 Screws 5 Universal_Screws_SEt' & @CRLF & _
'#2 Hammer 10 Claw_Hammer' & @CRLF & _
'#3 Led 10 Blue_Led' & @CRLF & _
'</body>' & @CRLF & _
'</html>'

$timer = TimerInit()
$aRegex = StringRegExp($sRead, "(?m)^#(\d+)\h+(.+?)\h+(.+?)\h+(.+?)\r?$", 3)
$u = UBound($aRegex)
Local $aRegex2D[$u][4]
$j = 0
For $i = 0 To $u-1 Step 4
    $aRegex2D[$j][0] = $aRegex[$i]
    $aRegex2D[$j][1] = $aRegex[$i + 1]
    $aRegex2D[$j][2] = $aRegex[$i + 2]
    $aRegex2D[$j][3] = $aRegex[$i + 3]
    $j += 1
Next
ReDim $aRegex2D[$j][4]
_ArrayDisplay($aRegex2D, 'Time : ' & Round(TimerDiff($timer) / 1000, 2) & ' sec')

Good attempt!, i will try your soluction and i will do i speed comparison between the two script ;)

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

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