替换两个字符串之间的文本 - Java(Android)

时间:2016-04-27 02:30:56

标签: java android string replace

如何替换“-webkit-transition: max-height 0.4s; -ms-transition: max-height 0.4s; -moz-transition: max-height 0.4s; -o-transition: max-height 0.4s; transition: max-height 0.4s; ”和“;start;”之间的所有文字

;end;

&安培;&安培;

imageTable = replaceMatching2(imageTable, ";start;", ";end;");

public static String replaceMatching2(String input, String lowerBound, String upperBound){
    String result = input.replaceAll("(.*?"+lowerBound + ")" + "(.*?)" + "(" + upperBound + ".*)", "");
    return result;
}

不适合我

我正在我已加载的imageTable = imageTable.replaceAll(";start;\\?.*?;end;", "$1foo$2"); 文件中替换此文本,因此有空格和一堆其他奇怪的字符,我有一种感觉阻止我使用常规语法。

编辑:这里你是示例请求

我想将其替换为输入

xml

没有(这个):;start; <w:drawing> <wp:inline distT="0" distB="0" distL="0" distR="0" wp14:anchorId="0FB83168" wp14:editId="284C1F2D"> <wp:extent cx="3251200" cy="2438400"/> <wp:effectExtent l="0" t="0" r="6350" b="0"/> <wp:docPr id="8" name="Picture 8"/> <wp:cNvGraphicFramePr> <a:graphicFrameLocks noChangeAspect="1" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/> </wp:cNvGraphicFramePr> <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"> <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"> <pic:nvPicPr> <pic:cNvPr id="0" name="P1460238.JPG"/> <pic:cNvPicPr/> </pic:nvPicPr> <pic:blipFill> <a:blip r:embed="rId10[imageid4]"> <a:extLst> <a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}"> <a14:useLocalDpi val="0" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main"/> </a:ext> </a:extLst> </a:blip> <a:stretch> <a:fillRect/> </a:stretch> </pic:blipFill> <pic:spPr> <a:xfrm> <a:off x="0" y="0"/> <a:ext cx="3251200" cy="2438400"/> </a:xfrm> <a:prstGeom prst="rect"> <a:avLst/> </a:prstGeom> </pic:spPr> </pic:pic> </a:graphicData> </a:graphic> </wp:inline> </w:drawing> ;end;

编辑:感谢经过更多研究后的快速回复,我使用了dcp发布的答案

" "

1 个答案:

答案 0 :(得分:0)

试试这个正则表达式

str = str.replaceAll("(.*;start;)(.*)(;end;.*)", "$1xxx$3");