简体   繁体   中英

Java regex to replace file path based on OS

I'm not very sure there is any regex to replace thoese things:

This is a string value read from a xml file saved through Linux machine

<pcs:message schema="models/HL7_2.5.model"/>

and this is the one saved in Windows machine

<pcs:message schema="model\HL7_2.5.model"/>

This is why the file getting an error in eclipse while exported in Linux and imported in Windows or vise versa.

Is there any regex to find and replace the value(slash and back slash) within String? (not XML parsing) based on working OS?

Thanks in advance

str = str.replaceAll("\\\\\\\\|/", "\\\\"+System.getProperty("file.separator"))

这应该照顾修复斜线:

String str = xml.replaceAll("\\\\|/", System.getProperty("file.separator"));

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