I’ve got a string like this: 02-09-10, 20:19 (1 dagen geleden). I need the 1 inside the brackets. I used this regex:
myStr.replace(/(.+*)\(([0-9]{1,}) dagen geleden\)/i, '$2')
But that doesn’t work… What to do?
Regards, dodo
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m not quite sure how I found myself back at this question, but I decided to expand on a point I made in the comments earlier. You’re using string.replace() where string.match() or regex.exec() would be more appropriate.
Furthermore, you can achieve your goal without even using regular expressions, which should be more efficient and more understandable if you’re not too savvy on regexes:
In fact, the regular expression you came up with is so explicit, you could change the first argument of slice to a number you know: