Oh yes, I had forgotten about that.

On 12/12/2022 14:59, Richard Kaye wrote:
Oh, so many ways to do this...

You could use Craig Boyd's VFP RegExp.FLL in place of the VBScript RegEx object.

--

rk

From: ProfoxTech <profoxtech-boun...@leafe.com> On Behalf Of António Tavares 
Lopes
Sent: Monday, December 12, 2022 8:55 AM
To: profoxt...@leafe.com
Subject: Re: Help with a regular expression

Paul,

An implementation of the NumberAtEnd method using Regular Expressions
(changed the pattern to give a bit more robustness):

m.acid1 = "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid (2.13)"
m.acid2 = "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid"

? NumberAtEnd(m.acid1) && 2.13
? NumberAtEnd(m.acid2) && FAIL

FUNCTION NumberAtEnd (Test AS String) AS String

LOCAL Regx AS VBScript_RegExp_55.RegExp
LOCAL Matches AS VBScript_RegExp_55.MatchCollection
LOCAL Result AS String

m.Regx = CREATEOBJECT("VBScript.RegExp")

m.Regx.Pattern = "(\(([0-9]+(\" + SET("Point") + "[0-9]+)?)\))$"

m.Matches = m.Regx.Execute(m.Test)

IF m.Matches.Count == 1
m.Result = m.Matches.Item(0).SubMatches.item(1)
ELSE
m.Result = "FAIL"
ENDIF

RETURN m.Result

ENDFUNC


On Mon, Dec 12, 2022 at 1:10 PM Paul Newton 
<paul.newton.h...@gmail.com<mailto:paul.newton.h...@gmail.com>>
wrote:

Hi all

I've been very quiet for a while so I thought it was about time I chimed
in again. I have come across the use of a regex expression in another
language which works like this:

acid1 = "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid (2.13)"
acid2 = "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid"

NumberAtEnd:= proc(S::string)
description
"Extract a parenthesized number, possibly containing periods, from
the end of a string":
local r;
if StringTools:-RegMatch("\\(([0-9.]*)\\)$<file://(([0-9.]*)/)$>", S, r$2) then 
r else
FAIL fi
end proc:

NumberAtEnd(acid1) returns "2.13"
NumberAtEnd(acid2) returns "FAIL"

How can this be done in VFP? Many thanks

Paul Newton
***

*



[excessive quoting removed by server]

_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: https://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: https://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: https://leafe.com/archives
This message: 
https://leafe.com/archives/byMID/d7d1cd5c-509e-fe3c-63e7-8c45fa153...@gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to