简体   繁体   中英

replace page number using Regular Expression in Javascript

I have a URL as Follow:

http://example.com/category/news/page/2/

I need to replace any number that comes at the end of URL which represents page number. If possible which I think it is, I want to use regular expression in case the domain changes, the code still works.

I am also using PHP ...

Could help me with a proper RegEx?

Find The Answer:

string.replace(/\/page\/[0-9]+/, '/page/' + pageNum);

pageNum can be any variable to replace the page number

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM