1

I am using the split function below to get a times value:

12:00

I now want to include another .split value (period):

12.00

I discovered I could use regex to achieve this but am failing to get a working result.

WORKING

var time = time.val().split(':')

FAILING (REGEX)

var time = time.val().split('/:|\./')

2 Answers 2

3

Regex is a type in itself in javascript, no need to put it quotes. Your code looks for a literal /:|\./.

Also, :|\. is [:.].

'12.00'.split(/[:.]/);

outputs

["12", "00"]
Sign up to request clarification or add additional context in comments.

1 Comment

A negligent oversite on my account. Thanks for spotting the obvious. Cheers Robin.
2

You can use like this.

var time = time.val().split(/\.|&/)

Comments

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.