B
bauer
Hi,
there's a DocBook XML file which I want to modify. The file contains
something like
....
<mediaobject>
<imageobject>
<imagedata fileref="PathToImage" format="ImgFormat"/>
</imageobject>
</mediaobject>
....
I just want to match the whole <mediaobject> thingy and prepend one
line which contains the PathToImage as a XML comment just like
<!-- PathToImage -->
My input to the matcher is the whole file as is. First I tried to get a
regex to match the whole thing
content = content.replaceFirst(
"<mediaobject>" +
"\\s*<imageobject>" +
"\\s*<imagedata fileref=\".*\".*/>" +
"\\s*</imageobject>" +
"\\s*</mediaobject>",
"<!-- Test -->"
);
But when I use a backref (like \0 for the whole match or \1 if I use
parentheses for the filename) in the replacement string like this:
"<!-- Test -->\0"
I just get
<!-- Test --> + this square char which cannot display here
The strange thing is that when I use exactly the same pattern with
Pattern.compile(regex).matcher(str).replaceAll(repl)
nothing matches (opposed to the Java API statment for
String.replaceAll()).
I tried Pattern.MULTILINE and Pattern.DOTALL in any combination. I
tried to use .* instead of \\s and even used \r?\n? for the line
endings ... nothing works.
Please can anyone help me?
_
Tom
there's a DocBook XML file which I want to modify. The file contains
something like
....
<mediaobject>
<imageobject>
<imagedata fileref="PathToImage" format="ImgFormat"/>
</imageobject>
</mediaobject>
....
I just want to match the whole <mediaobject> thingy and prepend one
line which contains the PathToImage as a XML comment just like
<!-- PathToImage -->
My input to the matcher is the whole file as is. First I tried to get a
regex to match the whole thing
content = content.replaceFirst(
"<mediaobject>" +
"\\s*<imageobject>" +
"\\s*<imagedata fileref=\".*\".*/>" +
"\\s*</imageobject>" +
"\\s*</mediaobject>",
"<!-- Test -->"
);
But when I use a backref (like \0 for the whole match or \1 if I use
parentheses for the filename) in the replacement string like this:
"<!-- Test -->\0"
I just get
<!-- Test --> + this square char which cannot display here
The strange thing is that when I use exactly the same pattern with
Pattern.compile(regex).matcher(str).replaceAll(repl)
nothing matches (opposed to the Java API statment for
String.replaceAll()).
I tried Pattern.MULTILINE and Pattern.DOTALL in any combination. I
tried to use .* instead of \\s and even used \r?\n? for the line
endings ... nothing works.
Please can anyone help me?
_
Tom