Help on regex script..

"Florent Gilain" <[email protected]>
Newsgroups gmane.comp.windows.autoit.user
Message-ID <6578ea627be7bf2cb6abcfa9d45d7f5d5e4ecbc6@localhost>
Hi all,

I have to create a script that will load a file containing lines separated
by tabulation.
Then, i need to verify data format using Regular expression; but i'm unable
to understand how it works in AutoIT...i have read the help file and
tutorial, but it seems i missed something...

File would contain :

Column 1 :  9 numbers with first number = 1 (example : 100000058)
Column 2 : 10 numbers with first number = 0 (example : 060254589)
Column 3 : 10 numbers with first number = 0 (example : 060254589)
Column 4 : valid email address

Example of file containing data :

CODE_TIERS	TELEPHONE	GSM	EMAIL
100000002	0955480155	0906604855	[email protected] (valid line)
1000000042	0955480101	091242847	himothercompany.com (invalid
line)


Here is what i have tryed :

$file = FileOpen("test.csv", 0)

; Check if file opened for reading OK
If $file = -1 Then

	MsgBox(0, "Error", "Unable to open file.")
	Exit
EndIf

$line_number = 0

; Read in lines of text until the EOF is reached
While 1
	$line = FileReadLine($file)
	If @error = -1 Then ExitLoop
	$line_number = $line_number+1
	MsgBox(0, "Line read :", $line)

	$array = StringSplit($line, Chr(9), 1)
	MsgBox(0, "Line number " & $line_number & " / Column 1 :",
$array[1])
	$RegExResult = StringRegExp($array[1], '([0]{1}[0-9]{8})', 1)
	If @error == 0 Then
    MsgBox(0, "Line number " & $line_number & " / Column 1 : KO", $array[1])
	EndIf
	
	MsgBox(0, "Line number " & $line_number & " / Column 2 :",
$array[2])
	$RegExResult = StringRegExp($array[2], '([0]{1}[0-9]{9})', 1)
	If @error == 0 Then
    MsgBox(0, "Line number " & $line_number & " / Column 2 : KO", $array[2])
	EndIf
	
	MsgBox(0, "Line number " & $line_number & " / Column 3 :",
$array[3])
	$RegExResult = StringRegExp($array[3], '([0]{1}[0-9]{9})', 1)
	If @error == 0 Then
    MsgBox(0, "Line number " & $line_number & " / Column 3 : KO", $array[3])
	EndIf
	
	MsgBox(0, "Line number " & $line_number & " / Column 4 :",
$array[4])
	$RegExResult = StringRegExp($array[4],
'(^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)
*)\.([A-Za-z]{2,})$)', 1)
	If @error == 0 Then
    MsgBox(0, "Line number " & $line_number & " / Column 4 : KO", $array[4])
	EndIf

Wend

FileClose($file)

Any idea of what i missed ?

Thanks

Florent
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.