diff --git a/doc/regexp.rdoc b/doc/regexp.rdoc index 51ea7720626f44..b9c89b1c8645bf 100644 --- a/doc/regexp.rdoc +++ b/doc/regexp.rdoc @@ -602,6 +602,23 @@ text appearing in tags without including the tags in the match: /(?<=)\w+(?=<\/b>)/.match("Fortune favours the bold") #=> # +== Absent operator + +Absent operator (?~pat) matches string which does +not match pat. + +For example, a regexp to match C comment, which is enclosed by /* +and */ and does not include */, using absent operator: + + %r[/\*(?~\*/)\*/] =~ "/* comment */ not-comment */" + #=> # + +This is often shorter and clearer than without absent operator: + + %r[/\*[^\*]*\*+(?:[^\*/][^\*]*\*+)*/] + %r[/\*(?:(?!\*/).)*\*/] + %r[/\*(?>.*?\*/)] + == Options The end delimiter for a regexp can be followed by one or more single-letter