Click here to Skip to main content
15,896,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here's my search text:
<time>2017-11-24T18:47:26Z</time>

Here's my regex expression for a FIND:
[0-9]T[0-9]

Here's my REPLACE expression:
[0-9]</date><time>[0-9]

And finally here's the result:
<time>2017-11-2[0-9]</date><time>[0-9]8:47:26Z</time>

What am I doing wrong here?

What I have tried:

That. That up there. What I really want is this:
<time>2017-11-24</date><time>18:47:26Z</time>


solution:

[EDIT]
FIND => "(\d+)T(\d+)"
REPLACE => "$1</date><time>$2"
[END EDIT]
Posted
Updated 28-Nov-17 18:31pm
v2
Comments
RedDk 28-Nov-17 20:50pm    
Thanks PC.

Just figured it another way as well:

(\d+)T(\d+)

with

$1"leftarrow""slash"date"rightarrow""leftarrow"time"slash""rightarrow"$2

(Boy is this stuff tricky)
Bryian Tan 28-Nov-17 21:43pm    
I don't get it, why make it so complicated? Assuming there only a "T" in the string then the code would look like
var s = "<time>2017-11-24T18:47:26Z</time>".Replace("T","</date><time>");


Output:
<time>2017-11-24</date><time>18:47:26Z</time>

Try it this way instead.


Here's my regex expression for a FIND:

(?<=\d)T(?=\d)

Here's my REPLACE expression:

</date><time>


(Just a quick guess.)

And you'll still have mal-formed XML.
 
Share this answer
 
v2
With a little stydy of xml date/time format, you would know that the 'T' is unique, so
FIND => "T"
REPLACE => "</date><time>"

is enough.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900