0

I am trying to retrieve and format the time via XML

<match time="8:20 PM" contestID="96775" formatted_date="16.09.2021" status="Not Started">

I am able to to get the string as 8:20 PM which I would like to string the PM or AM in the sting.

If I use the following:

myString.replace(/\D/g,'');

It strips the : which I still require.

Can anyone help me with the reg. expression I need for my issue?

UPDATE

Wanted result should be 8:20

1 Answer 1

1

you can use xpath to get the @time attribute. from that, you can split the time string by space :)

example: use xpath lib https://www.npmjs.com/package/xpath

var xpath = require('xpath')
var dom = require('xmldom').DOMParser

var xml = '<match time="8:20 PM" contestID="96775" formatted_date="16.09.2021" status="Not Started">';
var doc = new dom().parseFromString(xml);
var timeStr = xpath.select("string(/match/@time)", doc);
var [time, period] = timeStr.split(' ')
console.log(time, period)
Sign up to request clarification or add additional context in comments.

2 Comments

how do i do that?
Updated with sample code. not tested yet :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.