Skip to main content
Participant
September 29, 2011
Answered

modify display depending on data

  • September 29, 2011
  • 2 replies
  • 760 views

Everytime "ok" [a key word] appears, bold the date befor that. Data is coming from a feed.

Example:
Today is March 23, 2010, ok.
Yesterday was January 2, 2009, ok.
Tomorrow will be May 14, 2011, ok.

Result:  Today is March 23, 2010, ok.
Yesterday was January 2, 2009, ok.
Tomorrow will be May 14, 2011, ok.

So far...
<CFSET variable = #ReplaceNoCase(variable, "<ok.", "", "ALL")#>
Since date lenght varies each time: Look for two commas and two spaces before the key word and then bold it

Help please?

    This topic has been closed for replies.
    Correct answer Steve Sommers

    Did you try the reReplaceNoCase tag? The ",\s*ok" in the first parameter and the ", ok" in the second parameter handle the OK part of your requirement.

    2 replies

    Participant
    October 4, 2011

    I must apologize, as I was not clear in my question. Actually in the original feed, there are many dates in a paragraph. I only need to bold the date which is followed by a keyword.

    Example. This is the first date, January 1, 1980. This is the second date, March 2, 1990. This is another date, May 1, 2000, OK. This is the last date, June 1, 2010.

    “OK” being my keyword, the date before “OK” has to be bolded.

    So I need to start by looking for the keyword.

    Then figure out how many characters to move back and then bold that string.

    Steve SommersCorrect answer
    Legend
    October 4, 2011

    Did you try the reReplaceNoCase tag? The ",\s*ok" in the first parameter and the ", ok" in the second parameter handle the OK part of your requirement.

    Legend
    September 29, 2011

    I would have to do some research but reReplaceNoCase would be your friend:

    <cfset variables.str = reReplaceNoCase(variables.str,"((January|February|March|...) (\d){1,2}, (\d){4})),\s*ok","<strong>\\1</strong>, ok","ALL") />

    I know this is probably not 100%, but it should be close. (and the ... needs to be expanded to all the months)

    BKBK
    Community Expert
    Community Expert
    October 1, 2011

    Steve Sommers wrote:

    I would have to do some research but reReplaceNoCase would be your friend:

    <cfset variables.str = reReplaceNoCase(variables.str,"((January|February|March|...) (\d){1,2}, (\d){4})),\s*ok","<strong>\\1</strong>, ok","ALL") />

    I know this is probably not 100%, but it should be close. (and the ... needs to be expanded to all the months)

    Just a little tweak:

    reReplacenocase(variables.str,"((January|February|March|April|May|June|July|August|September|October|November|December) (\d){1,2}, (\d){4}),\s*ok","<strong>\1</strong>, ok","ALL")