qorelanguage / qore

Qore Programming Language
GNU General Public License v2.0
61 stars 10 forks source link

regex_extract issue (likely an endless loop) #2083

Closed gamato closed 7 years ago

gamato commented 7 years ago

While this works as expected:

$ qore -X 'regex_extract (" qaz\n\twsx\n\t edc", "(^[ \t]*)", Qore::RE_MultiLine + Qore::RE_Global)'
list: (3 elements)
  [0]=" "
  [1]=" "
  [2]="  "

The following never finishes:

$ qore -X 'regex_extract ("qaz\n\twsx\n\t edc", "(^[ \t]*)", Qore::RE_MultiLine + Qore::RE_Global)'

Note the missing space char in the searched string. It breaks if any leading whitespace is removed there (e.g. " qaz\n\twsx\nedc").

omusil24 commented 7 years ago

There's no need for the ^ character there...

gamato commented 7 years ago

What do you mean? Without ^ it would match whitespace in any place, while I want to match it only at the beginning of lines. But that's not the point here anyway. The point is that our regex_extract() runs into an infinite loop. And yes, it fails without ^ too, maybe even in more cases.

gamato commented 7 years ago

Btw, it's not about whitespace either, it gets stuck easily with any other characters. :-/