www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - regular expressions

reply 0ffh <spam frankhirsch.net> writes:
Hi,

just as a short note, is seems as if either

  a. the regex parser does not work as documented, or
  b. I have somehow messed up.

To be precise, http://www.digitalmars.com/ctg/regular.html says
that "." matches any character. I seem to have found at least
one exception, the newline character "\n".
Example the string "abc\ndef" is not matched by "^\".*\"$",
but is by "^\"(.|\n)*\"$".

Can anyone confirm?

Happy hacking,

	0ffh
Mar 11 2007
parent reply torhu <fake address.dude> writes:
0ffh wrote:
 Hi,
 
 just as a short note, is seems as if either
 
   a. the regex parser does not work as documented, or
   b. I have somehow messed up.
 
 To be precise, http://www.digitalmars.com/ctg/regular.html says
 that "." matches any character. I seem to have found at least
 one exception, the newline character "\n".
 Example the string "abc\ndef" is not matched by "^\".*\"$",
 but is by "^\"(.|\n)*\"$".
 
 Can anyone confirm?

It's standard in regex syntax that the dot doesn't match a newline. Should probably have been mentioned in the docs, though. Usually there's modifier than makes the dot match newlines too, but I can't see one on that page.
Mar 11 2007
parent 0ffh <spam frankhirsch.net> writes:
torhu wrote:
 0ffh wrote:
 [...]
 To be precise, http://www.digitalmars.com/ctg/regular.html says
 that "." matches any character. I seem to have found at least
 one exception, the newline character "\n".
 [...]

Should probably have been mentioned in the docs, though. [...]

Well, that would appear to be the reason, then. As I have found a trivial workaround, it's just as well.... :) Thanks, 0ffh
Mar 11 2007