How do I make a Javascript regular expression that will take this string (named url_string):
http://localhost:3000/new_note?date1=01-01-2010&date2=03-03-2010
and return it, but with the value of the date1 parameter set to a new date variable, which is called new_date_1?
There are better ways to manipulate URL than regex, but a simple solution like this may work:
[\d-]+matches a non-empty sequence of digits and/or dashes. If you really need to, you can also be more specific with e.g.\d{2}-\d{2}-\d{4}, or an even more complicated date regex that rejects invalid dates, etc.Note that since the regex makes the
"date1="prefix part of the match, it is also substituted in as part of the replacement.