我正在尝试从以下对象(已进行字符串化)中提取日期。
我是正则表达式的新手,不确定如何去做。
I tried /^(\d{4})\-(\d{1,2})\-(\d{1,2})$/gmi -> but it didnot work.
{"Date":"2016-05-16","Package Name":"com.myapp.mobile","Current Device Installs":"15912","Daily Device Installs":"41","Daily Device Uninstalls":"9","Daily Device Upgrades":"3","Current User Installs":"12406","Total User Installs":"23617","Daily User Installs":"27","Daily User Uninstalls":"8"}
最佳答案
不要在这里使用正则表达式。
进行JSON.parse(str).Date
,除非有充分的理由不这样做(您尚未在问题中说明一个)
如果要将字符串“ 2016-05-16”转换为Year,Month和day的3个变量(不使用日期库),我将使用.split()
:
dateArray = "2016-05-16".split("-")
var year = dateArray[0], month = dateArray[1], day = dateArray[2];
关于javascript - 日期的正则表达式模式匹配,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37557506/