XML title Regex pattern -
this input within article properties alter anything.
input:
<article xmlns:mml="http://www.w3.org/1998/math/mathml" xmlns:oasis="http://www.niso.org/standards/z39-96/ns/oasis-exchange/table" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" article-type="research-article" dtd-version="1.0" xml:lang="en">
output:
<article article-type="research-article" xmlns:mml="http://www.w3.org/1998/math/mathml" xmlns:xlink="http://www.w3.org/1999/xlink" >
i seek regex cant able further.
<article(?: [^>]+)? article-type="research-article"(?: [^>]+)? xmlns:mml="http://www\.w3\.org/1998/math/mathml"(?: [^>]+)?>
you can cut down regex as
<article (xmlns:mml=[^ ]*)\s.*(xmlns:xlink=[^ ]*).*(article-type=[^ ]*).*
the replacement string can <article $3 $1 $2>
which gives output as
<article article-type="research-article" xmlns:mml="http://www.w3.org/1998/math/mathml" xmlns:xlink="http://www.w3.org/1999/xlink">
for illustration see http://regex101.com/r/px1yi6/1
edit
if unsure order in property value may occure, improve utilize separate matches each of properties wish extract
for example
$str =~ m#(xmlns:mml[^ ]*)#; $mml=$1; $str =~ m#(xmlns:xlink[^ ]*)#; $xlink=$1; $str =~ m#(article-type[^ ]*)#; $type=$1; $output = "<article $type $mml $xlink >"; print $output;
will produce output as
<article article-type="research-article" xmlns:mml="http://www.w3.org/1998/math/mathml" xmlns:xlink="http://www.w3.org/1999/xlink" >bash-3.2$ nano xml.pl
xml regex perl
No comments:
Post a Comment