Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Searching with regular expressions
Message
From
02/11/2010 09:04:09
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
02/11/2010 08:55:03
Albert Beermann
Piepenbrock Service Gmbh & Cokg
Osnabrück, Germany
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Database:
MySQL
Miscellaneous
Thread ID:
01487847
Message ID:
01487848
Views:
120
This message has been marked as the solution to the initial question of the thread.
>Hello Everybody
>
>I have to extract special lines from a textfile.
>I know how to read the file line by line into a string.
>But i don't know how to search for regular expressions within a line?
>
>Example:
>
>xxxxxxxxx from="xyz@aabca.com" to="aaa@bbb.com" xxxxxxxxxxxxxxxx
>xxxxxxxxx from="xxxyz@adddaa.com" to="abab@xyz.com" xxxxxxxxxxxxxxxx
>xxxxxxxxx from="xyyyyyyyz@aaa.com" to="aaa@bbb.com" xxxxxxxxxxxxxxxx
>xxxxxxxxx from="xyzzzzz@aabca.com" to="aaa@bbb.com" xxxxxxxxxxxxxxxx
>xxxxxxxxx from="xzzzyz@aaa.com" to="aaa@bbb.com" xxxxxxxxxxxxxxxx
>
>Now i wont to extract all lines with from="*@aaa.com" &&our special customer
>or to="*@bbb.com" &&our special partner
>
>In this exampel * = all emails from the domain
>
>Any help welcomed
>Best regards
>Albert

Assuming you got them to a cursor called emails with field name "content":
create cursor foundAddresses (fromRec i, address m)
goRegEx = Createobject("VBScript.RegExp")
goRegEx.Pattern = "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
goRegEx.ignoreCase = .T.
goRegEx.Global = .T.

select emails
scan
  FindAddress(emails.content, recno('emails'))
endscan
select foundAddresses
browse

Procedure FindAddress(tcString, tnRecno)
loMatches = goRegEx.Execute(m.tcString)
FOR EACH loMatch IN loMatches
  insert into foundAddresses ;
    (fromRec, address);
     values ;
    (m.tnRecno, loMatch.Value)
ENDFOR
Update: I might have misunderstood your requirement. It might be like:
goRegEx = Createobject("VBScript.RegExp")
goRegEx.Pattern = '(from=\"(\w+([-+.]\w+)*)@aaa.com\")|(to=\"(\w+([-+.]\w+)*)@bbb.com\")'
goRegEx.ignoreCase = .T.
goRegEx.Global = .T.

append from myText.txt type sdf for goRegEx.Test( content )
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform