JavaScript regex - positive view - gives me syntax errors

This piece of regex (?<=href\=")[^]+?(?=#_)must match all href values ​​except the hash value and what follows in the href url. It seems to work fine under Regex debuggers / testers such as http://gskinner.com/RegExr/ but in javascript it causes a syntax error. If I remove <from (?<=), it works, however, this is not the positive look I am looking for.

I pull my hair out as usual thanks to regex lol

Please, help

+3
source share
3 answers

Lookbehinds , .

, , match(), :

href="(.+?)(?=#)

, :

var str = '<a href="foo#bar"></a>';
var matches = str.match(/href="(.+?)(?=#)/);

// matches[0] =  href="foo
// matches[1] = foo           // <-- this is what you want

:

[^] , . . , , ..

+3

, RegExr, , RegExr - Flash-, ActionScript, JavaScript. AS EcmaScript , JS, . PCRE, , PHP.

, JavaScript- , , JavaScript, .

+1

Source: https://habr.com/ru/post/1747882/


All Articles