Skip to main content
Inspiring
July 28, 2008
Question

how to use REFind

  • July 28, 2008
  • 2 replies
  • 749 views
Hi,

I am not really familiar yet with regular expressions. Can anyone help me how to check on a string pattern? I want to check a string if it has this pattern: {ts '2008-07-28 15:10:50'}

Or is there another way instead of using REFind? Thanks.
    This topic has been closed for replies.

    2 replies

    Inspiring
    July 28, 2008
    > Hi,
    >
    > I did something like this:
    >
    > <cfset strDate = "#now()#">
    >
    > <cfset strDateGet = REFind("{ts
    > '[1234567890][1234567890][1234567890][1234567890]-[1234567890][1234567890]-[1234
    > 567890][1234567890]
    > [1234567890][1234567890]:[1234567890][1234567890]:[1234567890][1234567890]'}",st
    > rDate)>
    >
    >
    > and it worked. thanks.

    Are you really wanting to match that pattern, do you you want to confirm
    the string is parseable as a timestamp?

    Your regex would accept an awful lot of combinations that pass the test for
    that pattern but are not time stamps.

    eg:

    {ts '0000-99-88 77:66:00'}

    It would also pass as true for:
    "any old nonsense before the match {ts '2008-07-28 15:10:50'} and then some
    other stuff here too". The reFind() would return a match there. Probably
    not what you want.


    You can also shorten some of your groups:

    [1234567890] is the same as [0-9] or \d

    And one can express series of the same match with curly-brace notation.
    Instead of the cumbersome:

    [1234567890][1234567890][1234567890][1234567890]

    One could have:

    \d{4}

    --
    Adam
    dongzkyAuthor
    Inspiring
    July 29, 2008
    Hi Adam,

    Thanks for the advice. I am not really familiar yet with regular expressions. Do you know any sites or online documentations that discusses more on regular expressions for CF? I have tried looking at cf documentations in Adobe but it only discusses few. Not enough informations. Thanks.

    And also, how do I check if it's a timestamp/date object or not? IsDate function don't do any good for this 'coz it will only check if a string is convertible to a date or not.
    dongzkyAuthor
    Inspiring
    July 28, 2008
    Hi,

    I did something like this:

    <cfset strDate = "#now()#">

    <cfset strDateGet = REFind("{ts '[1234567890][1234567890][1234567890][1234567890]-[1234567890][1234567890]-[1234567890][1234567890] [1234567890][1234567890]:[1234567890][1234567890]:[1234567890][1234567890]'}",strDate)>


    and it worked. thanks.