Search code examples
regexsafari

Regex Not compatible on Safari


I have a regular expression to pick the number. For ?page=2& this will return 2. My Expression is working fine for Chrome and Mozilla but not working on Safari.

Expression is: /(?<=page=)(.*?)(?=&)/

Please let me know what am I doing wrong here.


Solution

  • As look-arounds are not yet supported on Safari, capture the page= part, but then use a capture group to extract the part of interest:

    const url = "example.com?page=2&chapter=9";
    const page = /\bpage=([^&]*)/.exec(url)[1];
    
    console.log(page);