正则表达式——替换特定字符之前的所有空格

标签 regex intellij-idea

目标是做出类似的东西

This is some text=This is some text

成为:

This\ is\ some\ text=This is some text

我一直在玩各种不同的东西,我知道会在 (?==) 前面抓取空格/空白(例如“\”或\s),这似乎会选择直到 = 字符,但似乎没有什么使用 Intellij IDEA 的搜索和替换。

有什么建议吗?

最佳答案

复制评论中的答案,以便从“未回答”过滤器中删除此问题:

This - (\s)(?=.*=) should work. Replace it with \$1

~ 回答 Rohit Jain

OP 还证实了这一点:

That worked, though I used a literal space instead of the \s because it was picking up some additional white space I didn't want replaced. Also had to do some silly escaping for the replace (\\$1 )

关于正则表达式——替换特定字符之前的所有空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19305054/

相关文章:

java - Apache Flink Google Pub/Sub 连接器在 intellij idea 中运行抛出 NoClassDefFoundError

javafx - 从 jar 中加载图像

android - 即使已导入 WebView 类,也无法解析 loadUrl

regex - 在 Notepad++ 中使用查找和替换时引用正则表达式

regex - 为什么正则表达式不起作用? swift

java - 获取单引号或空格之间的字符串

regex - ElasticSearch按正则表达式排序

xml - 关于 xml <script> 元素的未转义字符的错误 IntelliJ 警告

android - 从设备 : EOF Android Studio 3. 2.1 获取屏幕截图时出现意外错误

regex - 检测正则表达式是否为指数