Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用正则表达式一次性替换hashtags_Java_Regex_Hashtag - Fatal编程技术网

Java 用正则表达式一次性替换hashtags

Java 用正则表达式一次性替换hashtags,java,regex,hashtag,Java,Regex,Hashtag,我想用Java中的等效标记替换字符串中的所有hashtag。示例: This is a #foo_bar #document about #nothing_but_tags! 将导致: This is a foo bar document about nothing but tags! 在一次通过的正则表达式替换中是否可能出现这种情况?一个标签可能包含很多单词。这里有一种方法可以通过一些小技巧来实现: String str = "#This is a #foo_bar #document a

我想用Java中的等效标记替换字符串中的所有hashtag。示例:

This is a #foo_bar #document about #nothing_but_tags!
将导致:

This is a foo bar document about nothing but tags!

一次通过的正则表达式替换中是否可能出现这种情况?一个标签可能包含很多单词。

这里有一种方法可以通过一些小技巧来实现:

String str = "#This is a #foo_bar #document about #nothing_but_tags!";
String res = str.replaceAll(" ?#|(?<=#\\w{0,100})_", " ").trim();
String str=“#这是一个关于#除了标签什么都没有#的#foo#u bar#文档!”;

String res=str.replaceAll(“?#|”(?规则是什么?删除哈希并用空格替换下划线?还有其他吗?是的,没有更多规则!什么是“等效标记”?我认为从示例中可以明显看出。谢谢你的回答。你能解释一下前瞻是如何工作的吗?@Mohsen This construct
(?