MMT designer MMT designer - 5 months ago 18
PHP Question

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?

Answer

Find The Answer:

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

pageNum can be any variable to replace the page number

Comments