Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ireland
    Posts
    122
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Regular expression

    Hi All

    I have an xml document which i am converting to html.
    There is a tag in the xml called <datecreated></datecreated>, and the date is in the format "dd-mm-yyyy hh:mm:ss".
    This tag occurs multiple times.

    I nedd to changes the contents of the tag to display the date to US format
    I.e. "mm-dd-yyyy hh:mm:ss"

    As you can see below I can get the contents of the tag, but dont know how to swap the dd & mm data around.

    Code:
    <cfset html = objXmlUtil.fixCDATABug(xmlTransform(REReplace(trim(qXML.xmlData),"<datecreated>[\d\w\s:-]+</datecreated>","<datecreated>[]</datecreated>","ALL"), trim(qXSL.stylesheet))) />
    Any help greatly appreciated.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Code:
    <cfset html = objXmlUtil.fixCDATABug(xmlTransform(REReplace(trim(qXML.xmlData),"<datecreated>(\d+)-(\d+)([^<]*)</datecreated>","<datecreated>\2-\1\3</datecreated>","ALL"), trim(qXSL.stylesheet))) />
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • Users who have thanked shyam for this post:

    tom123 (01-16-2008)

  • #3
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ireland
    Posts
    122
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Brilliant shyam, thanks.

    Could you possibly explain how the ([^<]*) part works?

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by tom123 View Post
    Could you possibly explain how the ([^<]*) part works?
    [^<] matches any character that is not a < which is the starting character of the tag termintator </datecreated> so, it essentially matches everything before </datecreated> which is after (\d+)-(\d+)
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •