VFP- Regular Expressions? 
Author Message
 VFP- Regular Expressions?

I found an object in VB (regexp) that matches a string against a 'string
pattern'.  It allows you to specify a 'pattern' with a specific character
notation.

Does VFP have anything similar, or has anyone written any similar functions?

Thanks,
    Gordy



Sun, 09 Mar 2003 03:00:00 GMT  
 VFP- Regular Expressions?
Gordy,
Here's a non-native (but workable) function (I saved off this question and
response from somewhere):

Quote:
>If I use WSH:s RegExp object I can 'save' matches and reference them with

$1 etc. if I use regEx.Replace. If I use regEx.Execute() instead it should
return a collection of all matches but I don't know how to access them from
VFP. If I use a syntax like Matches = regEx.Execute(string) it returns an
object named Matches that has no properties defined. Any clues?

Quote:
>***JS***

Here's an example converted to VFP from this MS example

=MessageBox('Test: RegExpTest("is.", "IS1 iS2 is3 Is4")'+chr(13);
 +chr(13)+RegExpTest("is.", "IS1 iS2 is3 Is4"))

Function RegExpTest(patrn, strng)
  *Dim regEx, Match, Matches  && Create variable.
  RetStr = ""
  regEx = CreateObject("VBScript.RegExp")   && Create regular expression.
  regEx.Pattern = patrn    && Set pattern.
  regEx.IgnoreCase = .T.   && Set case insensitivity.
  regEx.Global = .T.    && Set global applicability.
  Matches = regEx.Execute(strng) && Execute search.
  For Each Match in Matches   && Iterate Matches collection.
    RetStr = RetStr + "Match found at position "
    RetStr = RetStr + allt(str(Match.FirstIndex)) + ". Match Value is '"
    RetStr = RetStr + Match.Value + "'." + chr(13)
  Next
  RegExpTest = RetStr
  return RetStr
EndFunc

kenweber
***

Rick


Quote:
> I found an object in VB (regexp) that matches a string against a 'string
> pattern'.  It allows you to specify a 'pattern' with a specific character
> notation.

> Does VFP have anything similar, or has anyone written any similar
functions?

> Thanks,
>     Gordy



Sun, 09 Mar 2003 03:00:00 GMT  
 VFP- Regular Expressions?


Quote:
> I found an object in VB (regexp) that matches a string against a 'string
> pattern'.  It allows you to specify a 'pattern' with a specific character
> notation.

> Does VFP have anything similar, or has anyone written any similar
functions?

Hi Gordy
Nothing sophisticated but the LIKE() function is a regular expression
thingie.
? LIKE("*o?d*",'Gordy')
LIKE("*o?d*",'{*filter*}y')
LIKE("*o?d*",'sordid')
Any words containg o and d one letter apart. In SQL the widcard characters
are different
 SELECT name FROM Phonebook WHERE name LIKE '%o_d%'
The CHRTRAN function lets you test for the presence of any letters:
 ? UPPER(Students.name) = CHTRAN(UPPER(Students.name), 'WRJX','')
If any of the letter W,R,J or X, in any order, is presence they are removed
for the test and .F. would signal a hit.

-Anders

-Anders



Sun, 09 Mar 2003 03:00:00 GMT  
 VFP- Regular Expressions?
Thanks Rick.

I had actually found the VB version of this code out on MSDN.  I really
didn't think about it until I got your reply that RegExp is not a VB object,
but a VBScript object.  I don't understand all the technical details but I
guess since you can use VBScript to write html scripts, you don't need to do
anything, other than instantiate the object, to add the functionality to a
VFP function.  Way-cool!


Quote:
> Gordy,
> Here's a non-native (but workable) function (I saved off this question and
> response from somewhere):

> >If I use WSH:s RegExp object I can 'save' matches and reference them with
> $1 etc. if I use regEx.Replace. If I use regEx.Execute() instead it should
> return a collection of all matches but I don't know how to access them
from
> VFP. If I use a syntax like Matches = regEx.Execute(string) it returns an
> object named Matches that has no properties defined. Any clues?
> >***JS***

> Here's an example converted to VFP from this MS example

> =MessageBox('Test: RegExpTest("is.", "IS1 iS2 is3 Is4")'+chr(13);
>  +chr(13)+RegExpTest("is.", "IS1 iS2 is3 Is4"))

> Function RegExpTest(patrn, strng)
>   *Dim regEx, Match, Matches  && Create variable.
>   RetStr = ""
>   regEx = CreateObject("VBScript.RegExp")   && Create regular expression.
>   regEx.Pattern = patrn    && Set pattern.
>   regEx.IgnoreCase = .T.   && Set case insensitivity.
>   regEx.Global = .T.    && Set global applicability.
>   Matches = regEx.Execute(strng) && Execute search.
>   For Each Match in Matches   && Iterate Matches collection.
>     RetStr = RetStr + "Match found at position "
>     RetStr = RetStr + allt(str(Match.FirstIndex)) + ". Match Value is '"
>     RetStr = RetStr + Match.Value + "'." + chr(13)
>   Next
>   RegExpTest = RetStr
>   return RetStr
> EndFunc

> kenweber
> ***

> Rick



> > I found an object in VB (regexp) that matches a string against a 'string
> > pattern'.  It allows you to specify a 'pattern' with a specific
character
> > notation.

> > Does VFP have anything similar, or has anyone written any similar
> functions?

> > Thanks,
> >     Gordy



Mon, 10 Mar 2003 03:00:00 GMT  
 VFP- Regular Expressions?
Have you looked at LIKE()?

Quote:
> I found an object in VB (regexp) that matches a string against a 'string
> pattern'.  It allows you to specify a 'pattern' with a specific character
> notation.

> Does VFP have anything similar, or has anyone written any similar
functions?

> Thanks,
>     Gordy



Tue, 11 Mar 2003 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Regular expressions in VFP

2. Regular expressions for VFP

3. Regular Expressions

4. Anyone have Regular Expressions in FoxPro?

5. Regular index (.CDX) curruption

6. Printer refuses to print at regular intervals

7. SQL command to create a regular index

8. Unique or Regular Index?

9. change primary key ro regular key

10. VFP - Grid Dynamicbackcolor how to do expression with string

11. VFP 6 / Name Expression

12. HELP - Optimistic Row Buffering and Updating Expressions VFP 5.0a

 

 
Powered by phpBB® Forum Software