You almost got it. This work:
^rule\s+\"(.|\n|\r|\t)+\"(.|\n|\r|\t)+\bwhen\b(.|\n|\r|\t)+\bthen\b(.|\n|\r|\t)+\bend\b?$
Another solution:
^\s*rule\s+\"([^\"]+)\"[\s\S]+\s+when\s+([\s\S]+)\s+then\s+([\s\S]+)\send\s*$
Note: You missed the space and " -> \"
Tips:
- You can use \s for white space charcters.
- [^\"] for all non " character.
- [\s\S] for all characters.
- \b stop at
[a-zA-Z0-9_]
. \s+ stop at any non-whitespace character. It is just an extra precaution if any attribute start with a special character. - Use a program like Rad Software Regular Expression Designer. That will dramatically simplify editing and testing your regex code.