regex in balise html
-
hello after several searches I can’t find the regex that could remove the text between: <head> and </head>
<head>
dfgdfgdfg
dfgdfg
dfgdfg
dfgdfg
</head>thank you in advance
-
We have a FAQ entry on Generic Regex Formulas. The first link in that FAQ entry is Replacing in a specific zone of text. In your case, that “zone” would be the text between
<head>
and</head>
. So you can easily translate those as the START (BSR) and END (ESR) sequences of the zone, as described in the link found in the FAQ.In your case, the FR (Find Regex) would be
.*?
for "find as little as possible; the RR (Replacement Regex) would be the empty string (because you wanted to “remove the text between”); the BSR (Begin Search-Region Regex) would be<head>
; and the ESR (End Search-region Regex) would be</head>
. Plug those into the formula given, et voila!Good luck.
-
Okay, the generic expression doesn’t work as well as I thought in situations like this when you want to replace everything between the start and end of a range, rather than just pieces.
The easiest will be to just search for everything between
<head>
and</head>
, with FIND =<head>(?s:.*?)</head>
, REPLACE =<head></head>
, MODE = regular expression -
-
Regex: Select text between two tags/strings: You can try also:
FIND:
(?s)(<head>).*?(</head>)
REPLACE BY:\1\2
OR
FIND:
(<head>)\K[^>]*(?<!/)(</head>)|\1
REPLACE BY:</head>
OR
FIND:
(<head>)\K[\s\S]*?(</head>)|\1
REPLACE BY:</head>