At 11:58 02/09/2005, Brad Perkins wrote:
This one should be simple, but I'm just not getting it.

I need to create a pattern that match will match a comma delimited string, with no spaces around the commas. Trailing commas aren't allowed either.
This will be used in a form data validation method.


For example, I'd be looking at strings like the following:

1,2,3,4         is a match
1, 2, 3 , 4     isn't a match
1,2,3,4,        isn't (trailing comma)

The tricky part is that I don't know in advance how many items will be in the string, so I need to match repeating sub-patterns.
I have the Friedl book and recall this being covered there but can't find it if it was.


Any ideas?

-- Brad Perkins

I figured it out (or at least a start). Problem was that I was trying to figure out the pattern in a text editor that doesn't have the same level of regexp support that Active4D does.


This is code from and quick and dirty test page I wrote, but it might help someone out.

<%

import ("A4D.web")
import ("A4D.utils")

c_boolean ($isMatch)
c_text ($pattern;$subject)
$isMatch:= False

`Change $pattern and $subject to test.
`Don't forget start and end "/" pattern markers
$pattern := "/" + "^([0-9a-zA-Z]+)((,[0-9a-zA-Z]+)+)" + "/"
$subject := "this,is,a,test"
array text ($outMatches;0)
$isMatch:= regex match($pattern;$subject;$outMatches)
writep ("pattern: "+$pattern)
writep ("subject: "+$subject)
writep (choose($isMatch;"Match";"No Match"))
if ($isMatch)
        dump array ($outMatches)
end if
%>




_______________________________________________ Active4D-dev mailing list [email protected] http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Reply via email to