gpt4 book ai didi

java - 使用 java 的正则表达式查找子字符串

转载 作者:行者123 更新时间:2023-12-02 00:00:49 25 4
gpt4 key购买 nike

我需要在句子“Hello, call me XXX.”中找到子字符串。这个句子可能真的很长,唯一能帮助我识别名字是什么的事实是,名字总是在 fromat "call me"+space+name"+dot 中。尽管如此,句子也可以类似于 hello, call me. call me xxx.

Call me John. ⇒ John

Call me Call me John. ⇒ prohibited - confusing

Call me. Call me John. ⇒ John

Call me Call me John. ⇒ John

Call me Peter .Call me John. ⇒ John

Call me Peter. Call me John. ⇒ prohibited - more then one name...

名称可以是除\r、\n、\0 和点之外的任何字符序列。

如果有人可以帮助我定义正则表达式,我将不胜感激。我试图弄清楚两个多小时但没有成功......

最佳答案

正则表达式应该适合你:

"(?<=call me )[^.]*"

关于java - 使用 java 的正则表达式查找子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14895576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com