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.]*)\)$", 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 ***
*
Hi Paul,
you could always just use RegEx in VFP:
oRE = CreateObject("VBScript.RegExp") oRE.Pattern = "\(([0-9.]*)\)$" ? oRE.Test(acid1) ? oRE.Test(acid2)
That said, I haven't played with that pattern, but it doesn't return your desired result.
wOOdy
-----Ursprüngliche Nachricht----- Von: ProFox profox-bounces@leafe.com Im Auftrag von Paul Newton Gesendet: Montag, 12. Dezember 2022 14:10 An: profox@leafe.com Betreff: Help with a regular expression
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.]*)\)$", 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]
Hi Paul,
this would be a pure VFP solution: ********************************************** ? AcidTest("Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid (2.13)") ? AcidTest("Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid")
FUNCTION AcidTest(cText) LOCAL cResult, nCount
nCount = OCCURS("(", cText) cResult = STREXTRACT(cText, "(", ")", nCount) IF LEN(CHRTRAN(cDummy, "0123456789.", "")) # 0 cResult ="FAIL" EndIf Return cResult **********************************************
wOOdy
-----Ursprüngliche Nachricht----- Von: ProFox profox-bounces@leafe.com Im Auftrag von Paul Newton Gesendet: Montag, 12. Dezember 2022 14:10 An: profox@leafe.com Betreff: Help with a regular expression
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.]*)\)$", 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]
Hi wOOdy
Thanks for both your replies. I am not sure if it can be done at all using VBScript.RegExp but it would be nice if it could. Your AcidTest function has a problem with cDummy ...
Paul
On 12/12/2022 13:42, Jürgen Wondzinski wrote:
Hi Paul,
this would be a pure VFP solution:
? AcidTest("Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid (2.13)") ? AcidTest("Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid")
FUNCTION AcidTest(cText) LOCAL cResult, nCount
nCount = OCCURS("(", cText) cResult = STREXTRACT(cText, "(", ")", nCount) IF LEN(CHRTRAN(cDummy, "0123456789.", "")) # 0 cResult ="FAIL" EndIf Return cResult
wOOdy
-----Ursprüngliche Nachricht----- Von: ProFox profox-bounces@leafe.com Im Auftrag von Paul Newton Gesendet: Montag, 12. Dezember 2022 14:10 An: profox@leafe.com Betreff: Help with a regular expression
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.]*)\)$", 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]
Argh... Replace cDummy with cResult
-----Ursprüngliche Nachricht----- Von: ProFox profox-bounces@leafe.com Im Auftrag von Paul Newton Gesendet: Montag, 12. Dezember 2022 14:55 An: profox@leafe.com Betreff: Re: AW: Help with a regular expression
Hi wOOdy
Thanks for both your replies. I am not sure if it can be done at all using VBScript.RegExp but it would be nice if it could. Your AcidTest function has a problem with cDummy ...
Paul
Thanks wOOdy!
On 12/12/2022 14:00, Jürgen Wondzinski wrote:
Argh... Replace cDummy with cResult
-----Ursprüngliche Nachricht----- Von: ProFox profox-bounces@leafe.com Im Auftrag von Paul Newton Gesendet: Montag, 12. Dezember 2022 14:55 An: profox@leafe.com Betreff: Re: AW: Help with a regular expression
Hi wOOdy
Thanks for both your replies. I am not sure if it can be done at all using VBScript.RegExp but it would be nice if it could. Your AcidTest function has a problem with cDummy ...
Paul
[excessive quoting removed by server]
you can do this to get the positions, and then just get what is between the two positions.
store "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid (2.13)" to string store '(' to left_str store ')' to right_str
*acid2 = "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid"
clear
? rat(left_str, string) ? rat(right_str, string)
On Mon, Dec 12, 2022 at 7:10 AM Paul Newton paul.newton.hudl@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.]*)\)$", 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]
Thanks Virgil
I am not sure if your suggestion works in the case of "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid". I suspect it would end up as "methylsulfanyl" but I haven't tested it yet.
Paul
On 12/12/2022 13:48, Virgil Bierschwale wrote:
you can do this to get the positions, and then just get what is between the two positions.
store "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid (2.13)" to string store '(' to left_str store ')' to right_str
*acid2 = "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid"
clear
? rat(left_str, string) ? rat(right_str, string)
On Mon, Dec 12, 2022 at 7:10 AM Paul Newton paul.newton.hudl@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.]*)\)$", 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]
it would, because it would return a string instead of a numeric value, but I like the more elaborate ones that I'm seeing.
On Mon, Dec 12, 2022 at 8:01 AM Paul Newton paul.newton.hudl@gmail.com wrote:
Thanks Virgil
I am not sure if your suggestion works in the case of "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid". I suspect it would end up as "methylsulfanyl" but I haven't tested it yet.
Paul
On 12/12/2022 13:48, Virgil Bierschwale wrote:
you can do this to get the positions, and then just get what is between
the
two positions.
store "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid (2.13)"
to
string store '(' to left_str store ')' to right_str
*acid2 = "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid"
clear
? rat(left_str, string) ? rat(right_str, string)
On Mon, Dec 12, 2022 at 7:10 AM Paul Newton paul.newton.hudl@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.]*)\)$", 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]
acid1 = "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid (2.13)" acid2 = "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid"
string = acid1 store '(' to left_str store ')' to right_str pos1 = rat(left_str, string) pos2 = rat(right_str, string) ? SUBSTR(string,pos1+1,pos2-pos1-1)
"2.13"
string = acid2 store '(' to left_str store ')' to right_str pos1 = rat(left_str, string) pos2 = rat(right_str, string) ? SUBSTR(string,pos1+1,pos2-pos1-1)
"methylsulfanyl"
On 12/12/2022 14:12, Virgil Bierschwale wrote:
it would, because it would return a string instead of a numeric value, but I like the more elaborate ones that I'm seeing.
On Mon, Dec 12, 2022 at 8:01 AM Paul Newton paul.newton.hudl@gmail.com wrote:
Thanks Virgil
I am not sure if your suggestion works in the case of "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid". I suspect it would end up as "methylsulfanyl" but I haven't tested it yet.
Paul
On 12/12/2022 13:48, Virgil Bierschwale wrote:
you can do this to get the positions, and then just get what is between
the
two positions.
store "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid (2.13)"
to
string store '(' to left_str store ')' to right_str
*acid2 = "Methionine = (S)-2-amino-4-(methylsulfanyl)-butanoic acid"
clear
? rat(left_str, string) ? rat(right_str, string)
On Mon, Dec 12, 2022 at 7:10 AM Paul Newton paul.newton.hudl@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.]*)\)$", 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]
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.hudl@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.]*)\)$", 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]
Hi António
Subject to testing, that's it! Many thanks.
Paul
On 12/12/2022 13:54, António Tavares Lopes wrote:
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 Newtonpaul.newton.hudl@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.]*)\)$", 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]
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-bounces@leafe.com On Behalf Of António Tavares Lopes Sent: Monday, December 12, 2022 8:55 AM To: profoxtech@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.hudl@gmail.commailto:paul.newton.hudl@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]
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-bounces@leafe.com On Behalf Of António Tavares Lopes Sent: Monday, December 12, 2022 8:55 AM To: profoxtech@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.hudl@gmail.commailto:paul.newton.hudl@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]