-1

I copied a statement that aims to convert a string into Camel Case in Octave. The code is as following.

function camelStr = stringcamelcase (str)
    camelStr = lower(str)
    idx = regexp([' ' camelStr], '(?<=\s+)\S', 'start') -1;
    camelStr(idx) = upper(camelStr(idx));
end

But I receive this warning message.

warning: regexp: arbitrary length look behind patterns are only supported up to length 10

Looking for answers in the Internet, it seems is an issue about variable-length lookbehind-assertion, but I don't understand it and in all answers I read, people talk about it as all they understand it.

LudgerSB
  • 1
  • 3

1 Answers1

0

"arbitrary length look behind patterns are only supported up to length 10" message means that the \s+ pattern inside the (?<=...) positive lookbehind can match an unknown amount of whitespace chars beginning with 1. Since the upper bound is not defined, it is considered an "arbitrary length look behind pattern".

Since the message says these patternsare "only supported up to length 10", it means the (?<=\s+) is treated by your regex engine as if it were (?<=\s{1,10}), which is probably sufficient for the majority of your use cases. At any rate, you do not need + here, (?<=\s)\Sis fully equivalent to what you want to get. The (?<=\s+) and (?<=\s) are equivalent, because it is all the same if there is one or more or just one whitespace immediately to the left of the current position. If there is one or two or three whitespace chars, the match for \S will succeed. Else, it will fail.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563