简体   繁体   中英

Regular expression to terminate all characters between > and <

I have an string like below:

<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPrice>
  <m:StockName>IBM</m:StockName>
  </m:GetStockPrice>
</soap:Body>
</soap:Envelope>

i want to remove any thing including white spaces and newlines in between > and < and make this string in a single line.

how can i achieve this in java

If I understood you well you can use yourString.replaceAll(">[.\\\\s]*<", "><"))

Edit: Okay so you provided snippet with whitespaces only. Now try my code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM