0

I want to remove a single * character and any white space from the start of a string.

This is the regex I have /^\*{1}(?:\s+)?/

Here's a Rubular link http://rubular.com/r/r5i4FpQdK2

However Ruby is throwing a warning when I try to use it.

001:0> regex = /^\*{1}(?:\s+)?/
warning: nested repeat operator + and ? was replaced with '*': /^\*{1}(?:\s+)?/
=> /^\*{1}(?:\s+)?/

The actual test still works

002:0> "*  foo" =~ regex
=> 0

but I can't figure out what's causing the warning.

Any advice would be appreciated.

4

1 回答 1

1

而不是(?:\s+)?使用(?:\s*)或只是\s*

\s+允许一个或多个空格,以下?使其可选,可以用零个或多个空格替换为\s*

于 2013-10-29T05:35:40.467 回答