Java 带动态文本的正则表达式
我是Java的,我需要做一个替换,需要一个正则表达式的帮助Java 带动态文本的正则表达式,java,Java,我是Java的,我需要做一个替换,需要一个正则表达式的帮助 String temp = "/Users/john/core-xxx/testSomething.java" 我使用xxx作为动态文本的占位符。因此,我的目标是用名为testingPlatform的文本替换核心xxx。谢谢你的帮助 So System.println(someNewVariable);应该显示 "/Users/john/testingPlatform/testSomething.java" 你可以 String n
String temp = "/Users/john/core-xxx/testSomething.java"
我使用xxx作为动态文本的占位符。因此,我的目标是用名为testingPlatform的文本替换核心xxx。谢谢你的帮助
So System.println(someNewVariable);应该显示
"/Users/john/testingPlatform/testSomething.java"
你可以
String newTemp = temp.replaceAll("core-\\w+", "testingPlatform");
其中\w+
匹配一个或多个单词字符([a-zA-Z_0-9]
)
文件名可以包含unicode字符,这样更好
String newTemp = temp.replaceAll("core-\\p{L}+", "testingPlatform");
你可以
String newTemp = temp.replaceAll("core-\\w+", "testingPlatform");
其中\w+
匹配一个或多个单词字符([a-zA-Z_0-9]
)
文件名可以包含unicode字符,这样更好
String newTemp = temp.replaceAll("core-\\p{L}+", "testingPlatform");
使用此替换所有
replaceAll("yours","Replacement");
使用此替换所有
replaceAll("yours","Replacement");
您应该看看的
replace
和replaceAll
方法
在您的情况下,您应该执行以下操作:
System.println(temp.replaceAll("core-\\w+", "testingPlatform"));
您应该看看的
replace
和replaceAll
方法
在您的情况下,您应该执行以下操作:
System.println(temp.replaceAll("core-\\w+", "testingPlatform"));
不会是xxx。它可能是核心文档,或者核心sosIt不会是xxx。可以是核心单据或核心so在输入字符串“core xxx”中,xxx部分是动态的,因此可以是核心abc、核心efg等。。所以OP需要在输入字符串“core xxx”中使用正则表达式,xxx部分是动态的,所以它可以是core abc、core efg等。。所以OP想要一个RegexI刚才添加了一个关于如何获取用户所需内容的示例。我刚刚添加了一个关于如何获取用户所需内容的示例。