【发布时间】:2020-03-31 16:16:18
【问题描述】:
我收到这样的用户请求
site:www.example.com \"hello world\" \"hi abc\" where are you
我想从这个字符串中提取并保存 url 然后从上面的字符串中删除它,它应该看起来像这样"hello world" "hi abc" where are you 现在将剩余的字符串拆分为两个字符串数组
String str1 = {hello world, hi abc};
String str2 = {where, are, you};
我怎样才能在java中做到这一点? 用户查询可以是任何顺序。各种例子:
"hi" excitement site:www.example.com \"hello world\" \"hi abc\" where are you "amazing"
OR
Hello World friends
OR
Greeting is an "act of communication" human beings "intentionally"
【问题讨论】:
-
您可以使用regular expressions 和一些String functions 来实现此目的,例如
substring和replaceAll