Sign in to follow this  
Followers 0
Noobster24

Why is my pattern wrong in StringRegExp?

4 posts in this topic

Hi,

my program creates a txt-file with info from a website, sometimes there is '&' (HTML &), now i want to replace this '&'...

This is the function to pick the names and id's from the txt-file:

Func _SRE_Between($s_FilePath, $s_Start, $s_End)
    $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    If Not @error Then Return $a_Array
EndFunc

I thought that I could do it like this:

Func _SRE_Between($s_FilePath, $s_Start, $s_End)
    $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    $a_Array = StringRegExpReplace($a_Array, '(?:&)', '&')
    If Not @error Then Return $a_Array
EndFunc

But that isn't working, what's the right pattern? (Yes, I have read this article: http://www.autoitscript.com/forum/index.ph...l=stringregexp)

:D


Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.

Share this post


Link to post
Share on other sites



Hi,

my program creates a txt-file with info from a website, sometimes there is '&' (HTML &), now i want to replace this '&'...

This is the function to pick the names and id's from the txt-file:

Func _SRE_Between($s_FilePath, $s_Start, $s_End)
    $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    If Not @error Then Return $a_Array
EndFunc

I thought that I could do it like this:

Func _SRE_Between($s_FilePath, $s_Start, $s_End)
    $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    $a_Array = StringRegExpReplace($a_Array, '(?:&)', '&')
    If Not @error Then Return $a_Array
EndFunc

But that isn't working, what's the right pattern? (Yes, I have read this article: http://www.autoitscript.com/forum/index.ph...l=stringregexp)

:D

could you post a sampling of the data to be parsed?

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

If the 2nd $a_Array = is an array you aren't using it as an array but a only as a string, if it isn't an $a_Array then the string returned would be blank anyway.

$s = 'this is a test & only a test'
$Test = _SRE_Between($s, 'this', 'only')
If IsArray($Test) Then
    For $i = 0 To UBound($Test) - 1
        MsgBox(0,'info', $Test[$i])
    Next
EndIf

Func _SRE_Between($s_FilePath, $s_Start, $s_End)
  ;Local $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    Local $h_FRead = $s_FilePath
    Local $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    If IsArray($a_Array) And Not @error Then
        For $iCount = 0 To UBound($a_Array) - 1
            $a_Array[$iCount] = StringRegExpReplace($a_Array[$iCount], '(?:&)', '&')
        Next
        Return $a_Array
    EndIf
    Return 0
EndFunc

Edit:

And now that I "really" look at it, this would be much faster I'm sure:

$s = 'this is a test & only a test'
$Test = _SRE_Between($s, 'this', 'only')
If IsArray($Test) Then
    For $i = 0 To UBound($Test) - 1
        MsgBox(0,'info', $Test[$i])
    Next
EndIf

Func _SRE_Between($s_FilePath, $s_Start, $s_End)
   ;Local $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    Local $h_FRead = $s_FilePath
    $sReplace = StringRegExpReplace($h_FRead, '(?:&)', '&')
    Local $a_Array = StringRegExp($sReplace, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    If IsArray($a_Array) And Not @error Then Return $a_Array
    Return 0
EndFunc
Edited by SmOke_N

[center]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.[/center]

Share this post


Link to post
Share on other sites

If the 2nd $a_Array = is an array you aren't using it as an array but a only as a string, if it isn't an $a_Array then the string returned would be blank anyway.

$s = 'this is a test & only a test'
$Test = _SRE_Between($s, 'this', 'only')
If IsArray($Test) Then
    For $i = 0 To UBound($Test) - 1
        MsgBox(0,'info', $Test[$i])
    Next
EndIf

Func _SRE_Between($s_FilePath, $s_Start, $s_End)
 ;Local $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    Local $h_FRead = $s_FilePath
    Local $a_Array = StringRegExp($h_FRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    If IsArray($a_Array) And Not @error Then
        For $iCount = 0 To UBound($a_Array) - 1
            $a_Array[$iCount] = StringRegExpReplace($a_Array[$iCount], '(?:&)', '&')
        Next
        Return $a_Array
    EndIf
    Return 0
EndFunc

Edit:

And now that I "really" look at it, this would be much faster I'm sure:

$s = 'this is a test & only a test'
$Test = _SRE_Between($s, 'this', 'only')
If IsArray($Test) Then
    For $i = 0 To UBound($Test) - 1
        MsgBox(0,'info', $Test[$i])
    Next
EndIf

Func _SRE_Between($s_FilePath, $s_Start, $s_End)
  ;Local $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    Local $h_FRead = $s_FilePath
    $sReplace = StringRegExpReplace($h_FRead, '(?:&)', '&')
    Local $a_Array = StringRegExp($sReplace, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    If IsArray($a_Array) And Not @error Then Return $a_Array
    Return 0
EndFunc
Damn, that looks complicated, i'll taak a look at that later, must go now, thank you all :D

Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.

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  
Followers 0