Regular expression to find the date
Peter M. Brigham, MD
pmbrig at gmail.com
Thu Jan 5 11:03:08 EST 2012
I too am much in favor of using LC's text parsing rather than RegEx, which I admit is a prejudice (but one with foundation!). Beware, however, that the "is a date" function will return true for any number. I usually double-check this with something like:
put "sfgsfg gsfgs g 05/01/2011 t trtr" into tText
repeat for each word tWord in tText
if tWord is a date then
if howmany("/",tText) = 2 then
put tWord & cr after tFound
end if
end if
end repeat
put tFound
function howmany targetString,tText
put numtochar(8) into divChar
replace targetString with divChar in tText
set the itemdelimiter to divChar
put the number of items of tText into h
if char -1 of tText <> divChar then put h-1 into h
return h
end howmany
-- Peter
Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig
On Jan 5, 2012, at 5:23 AM, Bernard Devlin wrote:
> I just want to offer the simplest solution first. If there's a reason
> why this won't work, please say.
>
> put "sfgsfg gsfgs g 05/01/2011 t trtr" into tText
> repeat for each word tWord in tText
> if tWord is a date then put tWord & cr after tFound
> end repeat
> put tFound
>
> Maybe you are just looking to exeriment with regular expressions. But
> given your sample text and date format, the above works and will be
> readily readable when you return to in 6 months.
>
> Bernard
>
> On Thu, Jan 5, 2012 at 8:59 AM, paolo mazza <mazzapaoloitaly at gmail.com> wrote:
>> Hi All,
>> I have to find the date in a text. If I use this Regular Expression,
>> it finds the date (returns true) but it returns just the first chars
>> of the date..
>>
>> on mouseUp
>> put "sfgsfg gsfgs g 05/01/2011 t trtr" into FULLTEXT
>> put "((\d{2})|(\d))\/((\d{2})|(\d))\/((\d{4})|(\d{2}))" into MYSTRYNG
>> put matchText(FULLTEXT,MYSTRYNG,VAR0) into MYRESULT
>> put matchChunk(FULLTEXT,MYSTRYNG,VAR1, VAR2) into MYRESULT2
>> put MYRESULT && MYRESULT2 && VAR0 && VAR1 && VAR2
>> end mouseUp
>>
>> It returns "true true 05 16 17" instead of "true true 05/01/2011 16 25"
>>
>>
>> then if I change the text to search ...
>>
>> on mouseUp
>> put "sfgsfg gsfgs g 4/1/2011 t trtr" into FULLTEXT
>> put "((\d{2})|(\d))\/((\d{2})|(\d))\/((\d{4})|(\d{2}))" into MYSTRYNG
>> put matchText(FULLTEXT,MYSTRYNG,VAR0) into MYRESULT
>> put matchChunk(FULLTEXT,MYSTRYNG,VAR1, VAR2) into MYRESULT2
>> put MYRESULT && MYRESULT2 && VAR0 && VAR1 && VAR2
>> end mouseUp
>>
>> It returns "true true 4 16 16" instead of "true true 4/1/2011 16 24"
>>
>>
>> Why ? Any idea?
>>
>> All the best,
>>
>> Paolo Mazza
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list