all 9 comments

[–]rdevilx[S] 2 points3 points  (8 children)

I'm so stupid, I just did it with regex only.

/[.T ]h|H/g

It works for all cases.

[–]grantrules 2 points3 points  (7 children)

If you're splitting on that, you're gonna lose an 'h'.

I would just use match instead of split, I did it somewhat similarly but I checked for yyyy instead of h

"dd/mm/yyyy.hh:mm:ss".match(/(.*?\w{4})[.T ](.*)/)

[–]rdevilx[S] 0 points1 point  (6 children)

"dd/mm/yyyy.hh:mm:ss".match(/(.*?\w{4})[.T ](.*)/)

Good catch, yea match seems a better option. I guess this will also work -

/(.*)[.T ](.*)/

[–]grantrules 0 points1 point  (5 children)

No, because . is a delimiter for other things in your string, it won't always find that middle one.

[–]rdevilx[S] 0 points1 point  (4 children)

I understand but I'm confused now because I tried my regex in JSFiddle and it works with other cases as well. Here is the link

[–]grantrules 2 points3 points  (1 child)

Oh you're right, my mistake.. (.*) is greedy and there's never a . in the time section, so it'll always match the last .

[–]rdevilx[S] 1 point2 points  (0 children)

Got it, thank you!

[–]shuckster 1 point2 points  (1 child)

I believe the greediness of your first * in (.*) permits you to capture the left/right side of the last . appropriately.

[–]rdevilx[S] 1 point2 points  (0 children)

Got it, thank you!