1

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?

1
  • And what exactly is the problem with yourString.substring(6,19)? Commented May 15, 2014 at 16:53

3 Answers 3

3

That should be it

var numPart = "/Date(1317772800000)/".match(/(\d+)/)[1];
Sign up to request clarification or add additional context in comments.

Comments

3

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

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

Comments

1

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

2 Comments

No it won't; this will match his entire string.
@AndrewArnold no... it won't. Check out the link...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.