Sajjad Tahir
Sajjad Tahir

Reputation: 21

TCL regsub plus sign error

What is wrong with this? I can't seem to figure it out

regsub {+} $input { }

I get this error: couldn't compile regular expression pattern: quantifier operand invalid

Upvotes: 2

Views: 819

Answers (2)

Donal Fellows
Donal Fellows

Reputation: 137567

The + character is regular-expression metasyntax: it means match the preceding sub-RE one or more times. (For example, a+ matches one or more a characters.) Because of this, if you want to use a raw + you have to either escape it with a backslash (\+) or in a character set ([+]), or put the RE engine into one of its restricted modes; starting the RE with ***= makes the rest of the RE be a literal to match. Specializing to your case, ***=+ matches a plain +, and ***=++ matches two plusses in a row, etc.

Upvotes: 4

pynexj
pynexj

Reputation: 20688

Escape the + char:

regsub {\+} $input { }

Upvotes: 1

Related Questions