Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将符号和数字序列与空格匹配的正则表达式_Java_Regex_Pattern Matching_Removing Whitespace - Fatal编程技术网

Java 将符号和数字序列与空格匹配的正则表达式

Java 将符号和数字序列与空格匹配的正则表达式,java,regex,pattern-matching,removing-whitespace,Java,Regex,Pattern Matching,Removing Whitespace,我的模式有问题,我想找到一个单词(“abc”)、一个带数字的单词(“abc1”)、一个介于(“abc”)和一个单独的数字之间的空格,这个数字应该是“abc1” 这是我的模式:“(\\w*\\d*)[\\s]*”,但它的输出包含太多的空白,我不想这样做 因此,当要匹配的字符串为:def3abc2ghi2xyz1时,输出应为: “def 3” “abc 2” “ghi 2” “xyz 1” 我的输出看起来是一样的,但数字后面有额外的空格。我很感激你的帮助 更新你的正则表达式 (\w*\s*\

我的模式有问题,我想找到一个单词(“abc”)、一个带数字的单词(
“abc1”
)、一个介于(
“abc”
)和一个单独的数字之间的空格,这个数字应该是
“abc1”

这是我的模式:
“(\\w*\\d*)[\\s]*”
,但它的输出包含太多的空白,我不想这样做

因此,当要匹配的字符串为:
def3abc2ghi2xyz1
时,输出应为:

  • “def 3”

  • “abc 2”

  • “ghi 2”

  • “xyz 1”

    我的输出看起来是一样的,但数字后面有额外的空格。我很感激你的帮助

  • 更新你的正则表达式

    (\w*\s*\d*)[\s]*

    您可以阅读以了解正则表达式的工作原理。

    尝试使用以下正则表达式:

    请参见

    \\w+\\s?\\d*