Regex match between two regex expressions -


this has been driving me crazy, can't find solution works! i'm trying regex between couple of tags, bad idea i've heard necessary time :p have @ start <body class="foo"> foo can vary between files - <body.*?> search works fine locate copy in each file.

at end have <div id="bar">, bar doesn't change between files.

eg.

<body class="foo"> sometext more text <maybe tags> <div id="bar"> 

what need select between 2 tags not including them - between closing > on body , opening < on div - sometext maybe tags.

i've tried bunch of things, variations on (?<=<body.*>)(.*?)(?=<div id="bar">) i'm getting invalid expressions @ worst on notepad++, http://regexpal.com/ , no matches @ best.

any appreciated!

you attempting implement variable-length lookbehind in regular expression languages , notepad++ not support. assume using notepad++ can use \k escape sequence.

<body[^>]*>\k.*?(?=<div id="bar">) 

the \k escape sequence resets starting point of reported match , consumed characters no longer included. make sure have . matches newline checkbox checked well.

alternatively, can use capturing group , avoid using lookaround assertions.

<body[^>]*>(.*?)<div id="bar"> 

note: using capturing group, can refer group index "1" match result.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -