Java 如何使用正则表达式在短语后打印单词
它必须使用正则表达式用java编写Java 如何使用正则表达式在短语后打印单词,java,regex,Java,Regex,它必须使用正则表达式用java编写 我需要在“什么是”之后打印一个单词 输入: So what is java regex what is operator in java 输出: java operator java operator 只需使用lookback将紧跟其后的字符串与lookback中与模式匹配的字符串进行匹配 (?<=what is )\\S+ 如果必须是正则表达式,我会保持简单,并使用a来匹配和捕获“what is”后面的单词 注意:您需要引用匹配组#1以返回匹配
我需要在“什么是”之后打印一个单词 输入:
So what is java regex
what is operator in java
输出:
java
operator
java
operator
只需使用lookback将紧跟其后的字符串与lookback中与模式匹配的字符串进行匹配
(?<=what is )\\S+
如果必须是正则表达式,我会保持简单,并使用a来匹配和捕获“what is”后面的单词 注意:您需要引用匹配组
#1
以返回匹配结果
说明:
what # 'what'
\s # whitespace (\n, \r, \t, \f, and " ")
is # 'is'
\s # whitespace (\n, \r, \t, \f, and " ")
( # group and capture to \1:
\w+ # word characters (a-z, A-Z, 0-9, _) (1 or more times)
) # end of \1
java
operator
what\sis\s(\w+)
what # 'what'
\s # whitespace (\n, \r, \t, \f, and " ")
is # 'is'
\s # whitespace (\n, \r, \t, \f, and " ")
( # group and capture to \1:
\w+ # word characters (a-z, A-Z, 0-9, _) (1 or more times)
) # end of \1