Jump to content

Becoming crazy about StringRegExp


Recommended Posts

Hi,

i want to check if this sentence is in a txt-file.

Sentence:

<CENTER><BR>Result more than 50 records. Please, specify parameters of search.</CENTER><BR><BR>

I exspected this code to work, but it doesn't :S

$file = FileOpen('C:\Documents and Settings\Beheerder\Bureaublad\Andreas\Custom \~ OSS ~\office 2003.txt',0)

$test = StringRegExp ($file, '(.*)<CENTER><BR>Result more than 50 records. Please, specify parameters of search.</CENTER><BR><BR>(.*)',0)

If $test = 1 Then

MsgBox(0,"ja","ja")

Else

MsgBox(0,"Nee","nee")

EndIf

What's wrong with my pattern?

greetings,

Andreas

Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.
Link to comment
Share on other sites

  • Moderators

Hi,

i want to check if this sentence is in a txt-file.

Sentence:

I exspected this code to work, but it doesn't :S

What's wrong with my pattern?

greetings,

Andreas

do you just want: Result more than 50 records. Please, specify parameters of search. or all of it: <CENTER><BR>Result more than 50 records. Please, specify parameters of search.</CENTER><BR><BR>?

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.

Link to comment
Share on other sites

do you just want: Result more than 50 records. Please, specify parameters of search. or all of it: <CENTER><BR>Result more than 50 records. Please, specify parameters of search.</CENTER><BR><BR>?

The whole sentence, so:

<CENTER><BR>Result more than 50 records. Please, specify parameters of search.</CENTER><BR><BR>

The source of a website is written into a txt-file, i want to check if this sentence is in the txt-file...

Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.
Link to comment
Share on other sites

  • Moderators

Okay, i'll try...

edit: Nope, doesn't work..

Here try this:
$file = @DesktopDir & '\sre_test.txt'
$FindThis = '<CENTER><BR>Result more than 50 records. Please, specify parameters of search.</CENTER><BR><BR>'
If _SRE_Find($file, $FindThis) Then
    MsgBox(0, 'Info:', 'Found')
EndIf


Func _SRE_Find($s_FilePath, $s_Find)
    $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    $vFound = StringRegExp($h_FRead, '(?:' & $s_Find & ')')
    If $vFound Then Return $vFound
    Return 0
EndFunc

Edit:

Obviously you want to change the $File (location/name)

Edited by SmOke_N

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.

Link to comment
Share on other sites

Here try this:

$file = @DesktopDir & '\sre_test.txt'
$FindThis = '<CENTER><BR>Result more than 50 records. Please, specify parameters of search.</CENTER><BR><BR>'
If _SRE_Find($file, $FindThis) Then
    MsgBox(0, 'Info:', 'Found')
EndIf
Func _SRE_Find($s_FilePath, $s_Find)
    $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    $a_Array = StringRegExp($h_FRead, '(?:' & $s_Find & ')')
    If $a_Array Then Return $a_Array
    Return 0
EndFunc
I'll test it right now, i just want a 1 (true) returns if the sentence is found in the file or a 0 (false) if the sentence isn't found, not the place of the sentence.

i'll keep you informed...

Edit: It works, thank you! :D

Edited by Noobster24
Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.
Link to comment
Share on other sites

Here try this:

$file = @DesktopDir & '\sre_test.txt'
$FindThis = '<CENTER><BR>Result more than 50 records. Please, specify parameters of search.</CENTER><BR><BR>'
If _SRE_Find($file, $FindThis) Then
    MsgBox(0, 'Info:', 'Found')
EndIf
Func _SRE_Find($s_FilePath, $s_Find)
    $h_FRead = FileRead($s_FilePath, FileGetSize($s_FilePath))
    $vFound = StringRegExp($h_FRead, '(?:' & $s_Find & ')')
    If $vFound Then Return $vFound
    Return 0
EndFunc

Edit:

Obviously you want to change the $File (location/name)

Yeah, i know i must change the $File :D

Programs so far:Teh Serializer - Search for licenses for Nero - Windows - Office - Alcohol etc.
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...