Java 用于替换所有不在';之后的换行符的正则表达式';

Java 用于替换所有不在';之后的换行符的正则表达式';,java,regex,Java,Regex,我想问一下,是否有人可以帮助我使用regex,它将匹配所有\n,除了\n之后的 例如: 将更改为 testtest1test2; testtest1; testtest1; 此正则表达式可用于查找以下行:(?is means基本上不是a;后跟新行。您还可以在\r?之前添加一个\n,以接受可以出现在文档中的回车,尽管这取决于您的平台 只需将匹配项替换为”(一个空字符串)即可删除换行符。使用,这应该可以工作- Search for - (?<!;)\n Replace with - (E

我想问一下,是否有人可以帮助我使用regex,它将匹配所有
\n
,除了
\n
之后的

例如:

将更改为

testtest1test2;
testtest1;
testtest1;

此正则表达式可用于查找以下行:
(?is means基本上不是a;后跟新行。您还可以在
\r?
之前添加一个
\n
,以接受可以出现在文档中的回车,尽管这取决于您的平台

只需将匹配项替换为
(一个空字符串)即可删除换行符。

使用,这应该可以工作-

Search for   - (?<!;)\n
Replace with - (Empty string - '')
搜索-(?)?
演示

您可以使用:

// read complete file in a string
String data = new Scanner(new File("file.txt")).useDelimiter("\\Z").next();

// remove all newlines that aren't preceded by semi-colon
String repl = data.replaceAll("(?<!;)(\\r?\\n)+", "");
//读取字符串中的完整文件
字符串数据=新扫描仪(新文件(“File.txt”))。使用分隔符(\\Z”)。下一步();
//删除所有不带分号的换行符

String repl=data.replaceAll(“(?用于此操作的语言/工具是什么?将在java中完成。您尝试过任何操作吗?尝试并
.replaceAll(”)?
// read complete file in a string
String data = new Scanner(new File("file.txt")).useDelimiter("\\Z").next();

// remove all newlines that aren't preceded by semi-colon
String repl = data.replaceAll("(?<!;)(\\r?\\n)+", "");