3

Possible Duplicate:
How do I match any character across multiple lines in a regular expression?

I am currently making a software, working like Notepad++

I am using regex to find the words, and give them a color. However; I got stuck on coloring the multiple line comments.

Sample: /* This is a multiline comment */

Using my currently regex: /\*.*?\*/ - It is working properly until a newline is being placed.

So it matches: /*This, for instance!*/ But does not match:

/* This kind of comments
 - Where multiple lines is placed...
*/

So I was wondering, instead of using the [dot] for finding the words inside the comment, can I then use some other, match all operator?

  • I am using C#s class 'Regex'
Community
  • 1
  • 1
Rasmus Søborg
  • 3,292
  • 4
  • 27
  • 44
  • specifically [this answer](http://stackoverflow.com/a/2626317/1633117) – Martin Ender Sep 25 '12 at 16:08
  • 1
    A side note: you won't get far with regular expressions. You need a context-free grammar. For example what happens if `*/` is inside a string (assuming you create syntax highlighting for a programming language). – Prinzhorn Sep 25 '12 at 16:22

1 Answers1

3

Try this one might work for you.

/\**.*?\*/

RegexOptions must be set to MultiLine

Screenshot from RegexBuddy,

enter image description here

John Woo
  • 238,432
  • 61
  • 456
  • 464
  • any comments for downvote please? :) – John Woo Sep 25 '12 at 16:14
  • I didn't downvote, but isn't it exactly the other way round? Don't you need to set RegexOptions.Singleline? – Martin Ender Sep 25 '12 at 16:15
  • @m.buettner but the user want to be `multiline` write? – John Woo Sep 25 '12 at 16:16
  • Quoting from the page you linked yourself: "Specifies single-line mode. Changes the meaning of the dot (.) so it matches every character (instead of every character except \n)." ... so I guess this means, "Singleline" means "treat everything in the string as if it was in one line" – Martin Ender Sep 25 '12 at 16:17