Pergunta

In Ruby 1.8.7 the following regex warning: nested repeat operator + and * was replaced with '*'.

^(\w+\.\w+)\|(\w+\.\w+)\n+*$

It does work in Ruby 2.0 though?

http://rubular.com/r/nRUSP5LNZA

Foi útil?

Solução

A nested operator works, but is warned because it is useless. \n+* means:

  • Zero or more repeatition of
  • One or more repeatition of
  • \n

which is equivalent to a more simple expression \n*, which means:

  • Zero or more repeatition of
  • \n

There is no reason to use \n+*. Ruby regex engine was replaced in Ruby 1.9 and in Ruby 2.0, and if there are any differences, then it is simply that the newer engine does not check for warnings as the older one did.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top