RegExp in ActionScript 3: How to exclude a complex prefix?

AS3 RegExp engine (and ECMAScript-based JavaScript) do not support complex "lookbehind" expressions . (lookahead expressions are fully supported.)

For instance:

 (?<=<body>)(.*?)(?=<\/body>)

will work but

(?<=<body\b[^>]*>)(.*?)(?=<\/body>)

will not work in AS3.

I need to match a complex prefix, but exclude it in the final match. In the above example; I am trying to get body contents in HTML text, but DO NOT open and close body tags. And the actual test text is as follows:

<body bgcolor="#EEEEEE">
Some content here...
</body>
0
source share
3 answers

, var regExp:RegExp = /<body>(.*?)<\/body>/i; , body, \1 $1 , :

http://livedocs.adobe.com/flex/3/html/help.html?content=12_Using_Regular_Expressions_09.html

0

JavaScript RegExp, ...

, , . - , :

(?:<body\b[^>]*>)(.*?)(?:<\/body>)

, ( / ).

0

quoo; .

var re:RegExp = new RegExp(/(<body\b[^>]*>)(.*?)(<\/body>)/gis); }
return strHTML.replace(re, "$2");

This returns only content without body tags. No need to worry about lookbehinds and / or looks.

Thank you all..

0
source

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


All Articles