根据关键字搜索句子,并返回符合关键字的单词



我需要获得某个公司的URL链接,然后对该URL进行一些处理。目前我正在尝试使用PatternMatcher来获得单词,但没有按照我的要求获得。

val p: Pattern = Pattern.compile("abc.com")
val m: Matcher = p.matcher("Hi, welcome to ABC Website. test-page.abc.com/?12345 link to your profile.")
if (m.find()) {
AppLog.d("UnitTest", "Found : ${m.group()}")
} else {
AppLog.d("UnitTest", "Not found")
}

运行这个,我得到这个输出

找到:abc.com

有没有办法让我获得整个链接?任何Regex都可以用来让我得到这个?

找到:test-page.abc.com/?12345

根据我的评论,您可以考虑以下内容:

S*abc.comS*

这将提取一个子字符串,该子字符串包含abc.com,但包括除空白字符以外的所有前导和尾随字符。

最新更新