url.replace(/\/?offset=\d+/g, ''); 

This regular search is looking for the string? Offset = any number, but do I need to make another sign? was optional (that is, it may or may not be). I tried it like this

 url.replace(/\/?\*offset=\d+/g, ''); 

But it did not work: (How to write such a condition correctly?

  • This regular season is not looking for what you describe. - Alexey Ten
  • It is better to describe the problem completely, as well as where you will solve it. For example, if this is nodejs, then it may be easier to use the url mod - Alexey Ten

2 answers 2

You can still like this:

 \??offset=\d+ 

    So it worked:

     url.replace(/\?*offset=\d+/g, '') 
    • it worked like this - amijin
    • one
      This expression also works for the string ??????offset=123 , which is hardly the correct behavior of the program - Dmitriy Simushev
    • Well, well, I do not need signs? - amijin