Invalid regular expression error

前端 未结 4 776
清酒与你
清酒与你 2021-01-19 06:35


I\'m trying to retrieve the category part this string \"property_id=516&category=featured-properties\", so the result should be \"featured-properties\

4条回答
  •  滥情空心
    2021-01-19 07:02

    Positive lookbehinds (your ?<=) are not supported in JavaScript environments that do not comply with ECMAScript 2018 standard, which is causing your RegEx to fail.

    You can mimic them in a whole bunch of different ways, but this might be a simpler RegEx to get the job done for you:

    var url = "property_id=516&category=featured-properties"
    var urlRE = url.match(/category=([^&]+)/);
    // urlRE => ["category=featured-properties","featured-properties"]
    // urlRE[1] => "featured-properties"
    

    That's a super-simple example, but searching StackOverflow for a RegEx pattern to parse URL parameters will turn up more robust examples if you need them.

提交回复
热议问题