Java 用正则表达式一次性替换hashtags
我想用Java中的等效标记替换字符串中的所有hashtag。示例: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
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(?