Jump to content

Recover string in another string


Recommended Posts

Hi,

I have a small problem

I would recover a string in another string automatically. I have many html files.

And I would recover all strings between <script> and </script> in entire each file.

But I don't know how to proceed, to do this....

Thanks

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Link to comment
Share on other sites

But the _StringBetween() function fail when the two strings are equal.

For example if I want find string between "1" and "1", the function return -1 :)

I took a bad example with <script> and </script>, because there are two different strings...

$file = 'path to html-file'
$source = FileRead($file)
$ret = StringRegExp($source, '(?:<script>)(.*)(?=</script>)', 3)
$sScript = $ret[0]

this script is not working properly because when I run this, the result return the string between the first <script> and the last </script>.

Me I want to recover each string between <script> and </script>.

Edited by jerem488

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Link to comment
Share on other sites

  • 2 weeks later...

I hope this RegExp pattern help you :)

$file = 'path to html-file'
$source = FileRead($file)
$ret = StringRegExp($source, '(?:<script>)(?s)(.*?)(?:</script>)', 3)
_Array2Console($ret)

Func _Array2Console(ByRef $array);Enumerate Array in SciTE Console or in Console when compiled as a Console application
    Local $i
    If IsArray($array) Then
        Switch UBound($array, 0)
            Case 1
                For $i = 0 To UBound($array) - 1
                    ConsoleWrite("[" & $i & "] = " & $array[$i] & @CRLF)
                Next
                ConsoleWrite(@CRLF)
            Case Else
                ConsoleWrite("Error : Max Array Dimension Supported = 1 >> Current is " & UBound($array, 0) & @CRLF)
        EndSwitch
    Else
        ConsoleWrite("[not array] String = " & $array & @CRLF)
    EndIf
EndFunc   ;==>_Array2Console
Edited by taz742
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...