문제

I have the following string

/Date(1317772800000)/

I want to use a Javascript regular expression to extract the numerical portion of it

1317772800000

How is this possible?

도움이 되었습니까?

해결책

That should be it

var numPart = "/Date(1317772800000)/".match(/(\d+)/)[1];

다른 팁

No need for regex. Use .substring() function. In this case try:

var whatever = "/Date(1317772800000)/";
whatever = whatever.substring(6,whatever.length-2);

This'll do it for you: http://regex101.com/r/zR0wH4

var re = /\/Date\((\d{13})\)\//;
re.exec('/Date(1317772800000)/');
=> ["/Date(1317772800000)/", "1317772800000"]

If you don't care about matching the date portion of the string and just want extract the digits from any string, you can use this instead:

var re = /(\d+)/;
re.exec('/Date(1317772800000)/')
["1317772800000", "1317772800000"]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top