RE: E-mail pattern Was: Help on regex script..

"Florent Gilain" <[email protected]>
Newsgroups gmane.comp.windows.autoit.user
Message-ID <849826dee3a66fa23798c2aeef33096f7315a21d@localhost>
Hello Valery,
 
Sorry, i'm still unable to make it work..
 
here si my new autoit code :
 
$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
 
$codetiersPattern = '[1]{1}[0-9]{8}'
$telephonePattern = '[0]{1}[12345689]{1}[0-9]{8}'
$gsmPattern = '[0]{1}[6]{1}[0-9]{8}'
$emailPattern = '[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z](?i)'
 
; Read in lines of text until the EOF is reached
While 1
 ; On incrémente le compteur du nombre de lignes
 $line_number = $line_number+1
 ; On récupère le contenu de la ligne en cours / Get file current line
content
 $line = FileReadLine($file)
 If @error = -1 Then ExitLoop
 
 MsgBox(0, "Line read :", $line)
 ; On évite la premiere ligne qui contient les en-têtes / don't act on first
line because it only contains headers of the columns
 If $line_number == 1 Then
  MsgBox(0,"Information","Je lis la premiere ligne")
 Else
  ; On récupère chaque champ dans un tableau de variable en utilisant la
tabulation comme séparateur / Get each column value (cvs file with
tabulation separator) in an array
  $array = StringSplit($line, Chr(9), 1)
  
  $RegExResult = StringRegExp($array[1], $codetiersPattern, 1)
  If $RegExResult <> 0 Then
     MsgBox(0, "Line number " & $line_number & " / Column 1 : KO",
$array[1])
  EndIf
  
  $RegExResult = StringRegExp($array[2], $telephonePattern, 1)
  If $RegExResult <> 0 Then
     MsgBox(0, "Line number " & $line_number & " / Column 2 : KO",
$array[2])
  EndIf
  
  $RegExResult = StringRegExp($array[3], $gsmPattern, 1)
  If $RegExResult <> 0 Then
     MsgBox(0, "Line number " & $line_number & " / Column 3 : KO",
$array[3])
  EndIf
  
  $RegExResult = StringRegExp($array[4], $emailPattern, 1)
  If $RegExResult <> 0 Then
     MsgBox(0, "Line number " & $line_number & " / Column 4 : KO",
$array[4])
  EndIf
 EndIf
WEnd
 
FileClose($file)
 
any idea of what i missed ? i get a KO result (not OK) even if it should be
ok
 
florent

  _____  

De : [email protected] [mailto:[email protected]] De la
part de valery_vi
Envoyé : mardi 30 janvier 2007 07:26
À : [email protected]
Objet : [AutoIt] E-mail pattern Was: Help on regex script..



But it isn't perfect and is a subject of many articles
See, for example:
http://www.regular- <http://www.regular-expressions.info/email.html>
expressions.info/email.html

Valery

--- In AutoItList@yahoogro <mailto:AutoItList%40yahoogroups.com> ups.com,
"valery_vi" <shehrer1@...> wrote:
>
> About e-mail. I found this nice pattern
> 
> $Pattern = '[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z](?i)'
> 
> $RegExResult = StringRegExp($array[1], $Pattern, 1)
> 
> It works with ARegExp script, too.
> 
> Valery
> 
> 
> --- In AutoItList@yahoogro <mailto:AutoItList%40yahoogroups.com> ups.com,
"valery_vi" <shehrer1@> wrote:
> >
> > Florent,
> > 
> > I'm not expert in regexp but maybe it will be helpful to use 
regexp 
> > without grouping parenthethis '(...)'
> > 
> > > Column 1 : 9 numbers with first number = 1 (example : 
100000058)
> > $RegExResult = StringRegExp($array[1], '[1][0-9]{8}', 1)
> > > Column 2 : 10 numbers with first number = 0 (example : 
060254589)
> > > Column 3 : 10 numbers with first number = 0 (example : 
060254589)
> > $RegExResult = StringRegExp($array[1], '[0][0-9]{9}', 1)
> > 
> > > Column 4 : valid email address
> > It is expert's case.
> > ;-(
> > 
> > 
> > Valery
> > 
> > --- In AutoItList@yahoogro <mailto:AutoItList%40yahoogroups.com>
ups.com, "Florent Gilain" 
> > <florent.gilain@> wrote:
> > >
> > > 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 me@ (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
> > >
> >
>



 


[Non-text portions of this message have been removed]
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.