Domanda

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

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top