I have a string that contains a value that looks like this.
somevalueshere=123&page=3&someothervalues=123
and I want to replace the number 3 with 1 . So it would look like page=1
The number is always a positive whole number like 1,2,3,4,5,6,7
All I have so far is
.replace("page=" + 'some number reg ex here', "page=1")
The regular expression for a number (without decimals) is \\d+
. \\d
matches any numeric digit, and +
means at least one of the preceding pattern.
str = str.replace(/\bpage=\d+/, 'page=1');
This is very basic regular expression syntax. If you don't already know it, you should read the tutorial at http://www.regular-expression.info .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.