Bug 1249 – regular expression pattern [.] not matches any character

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-05-26T18:21:00Z
Last change time
2014-02-16T15:25:33Z
Assigned to
bugzilla
Creator
yidabu

Comments

Comment #0 by yidabu — 2007-05-26T18:21:30Z
regular expression pattern [.] not matches any character The following code shows it: import std.regexp; import std.stdio; void main() { char[] s = "a b"; char[] p = "[.]+"; s = std.regexp.sub(s, p, ""); writefln("s=%s,",s); // s not changed }
Comment #1 by wbaxter — 2007-05-26T23:52:59Z
I think '.' and other special characters lose their special meaning inside a character class. So [.()$^] should match either a period, a paren, a dollar-sign, or a caret, and nothing else. If it's not documented as such then maybe this is a documentation needs to make that clear. That sort of behavior is pretty common of regexp implementations. Why would you want to put a 'match any character' symbol inside a 'match any of these characters' construct. [.] would mean the same thing as a plain period.
Comment #2 by yidabu — 2007-05-27T06:23:18Z
> Why would you want to put a 'match > any character' symbol inside a 'match any of these characters' construct. [.] > would mean the same thing as a plain period. since . not match newline, I try [.\s] to match anything, but failed. the only way is (.|\s) PCRE: Note that special characters do not retain their special meanings inside [], with the exception of \\, \^, \-,\[ and \] match the escaped character inside a set.
Comment #3 by witold.baryluk+d — 2007-06-21T11:19:31Z
(In reply to comment #1) > I think '.' and other special characters lose their special meaning inside a > character class. So [.()$^] should match either a period, a paren, a > dollar-sign, or a caret, and nothing else. You are rigth, but actually ^ must be escaped: [.()$\^]. And IMHO this is not a bug. One can discuss but most of regular expression eninges also does so.
Comment #4 by bugzilla — 2007-06-28T22:12:53Z
Works as designed.