0

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

kreek
  • 8,774
  • 8
  • 44
  • 69
  • `x+*` is not a construct I'm familiar with; is that a Ruby thing? Also, why not just use `^(\w+\.\w+)\|(\w+\.\w+)$`? – p.s.w.g Feb 07 '14 at 19:11
  • actually @p.s.w.g I'm sure my regex is wrong too, what I actually want is that there must be two files separated by a pipe on one or more lines, which seems to be working in http://rubular.com/r/nRUSP5LNZA – kreek Feb 07 '14 at 19:21
  • Figured it out `/^((\w+\.\w+)\|(\w+\.\w+)(\r\n)*)*$/` – kreek Feb 07 '14 at 19:30

1 Answers1

3

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.

sawa
  • 165,429
  • 45
  • 277
  • 381