Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个String,我需要用逗号分割它,但是如果前面的字符是\,那么这部分不应该被分割。
例如从String str = "first,second\\,third,fourth"我需要String[] strs = { "first", "second\\,third", "fourth" }
String str = "first,second\\,third,fourth"
String[] strs = { "first", "second\\,third", "fourth" }
像这样的东西?
String str = "first,second\\,third,fourth"; String[] strs = s.split("(?<!\\\\),");
查看 java.utils.regex.Pattern 文档以获得解释。