regex - Find text between key phrases -
i have var have text in:
<cfsavecontent variable="foo"> element.password_input= <div class="holder"> <label for="$${input_id}" > $${label_text}</label> <input name="$${input_name}" id="$${input_id}" value="$${input_value}" type="password" /> </div> # end element.password_input element.text_input= <div class="ctrlholder"> <label for="$${element_id}" > $${element_label_text}</label> <input name="$${element_name}" id="$${element_id}" value="$${element_value}" type="text" class="textinput" /> </div> # end element.text_input </cfsavecontent>
and trying parse through var of different element type(s) here have far:
ar = rematch( "element\.+(.*=)(.*?)*", foo )
but giving me part:
element.text_input= element.password_input=
any appreciated.
your immediate problem default .
doesn't include newlines - need use flag (?s)
in regex this.
however, enabling flag still wont result in present regex doing you're expecting do.
a better regex be:
(element\.\w+)=(?:[^##]+|##(?! end \1))+(?=## end \1)
you listfirst(match[i],'=')
, listrest(match[i],'=')
name , value. (rematch doesn't return captured groups).
(obviously #s above doubled escape them cf.)
above regex dissected is:
(element\.\w+)=
match element.
, alphanumeric, placed capture group 1, match =
character.
(?: [^##]+ | ##(?! end \1) )+
match number of non-hash characters, or hash not followed ending token (using negative lookahead (?!...)
) , referencing capture group 1 (\1
), repeat many times possible (+
), using non-capturing group ((?:...)
).
(?=## end \1)
lookahead (?=...)
confirm variable's ending token present.
Comments
Post a Comment