简体   繁体   中英

Using multiple deliminators for javascript .split function

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

您可以这样使用。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM