简体   繁体   中英

Issue with regex expression used to extract timestamps from XML file

I am aiming to implement regex into my C++ program in an attempt to extract timestamps, among other things from an XML file. Right now I am focusing on creating a regex expression to extract 6 timestamps in particular from the XML file. Unfortunately, I my regex expression does not seem to be locating the 6 timestamps I want it to. The expression I have created is: \\2\\0\\1\\4\\\\-\\0\\7\\-\\0\\8\\T\\1\\8\\:\\1\\4\\:\\.\\.\\\\.\\7\\1\\6\\Z . If you look at the XML file which I have linked below, I am trying to extract the timestamps from 6 lines in particular(lines 72,75,78,81,84,and 87). Could someone possibly help me point out what is being done wrong? Sorry, I'm just getting familiarizing myself with Regex for the first time. I am using http://regexr.com/ to test my expressions.

Link to XML file: http://pastebin.com/5hMy9RzK

Six timestamps which I want my regex expression to locate:

timestamp="2014-07-08T18:14:17.716Z"

timestamp="2014-07-08T18:14:18.716Z

timestamp="2014-07-08T18:14:19.716Z

timestamp="2014-07-08T18:14:20.716Z

timestamp="2014-07-08T18:14:21.716Z

timestamp="2014-07-08T18:14:22.716Z

Your expression looks strange, you are escaping every literal character with a \\ which is usually only used for special characters.

Is this what you're looking for?

\d\d\d\d-\d\d-\d\d\w\d\d:\d\d:\d\d\.716Z

Example: http://regexr.com/3cbs2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM