문제

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('/:|\./')
도움이 되었습니까?

해결책

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"]

다른 팁

You can use like this.

var time = time.val().split(/\.|&/)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top