Search code examples
c++regexlex

How to catch multiple rows in lex


I want to make a regex for multiple rows sample. I tried like this:

^"SAMPLE_SIGN"."\n".SAMPLE_SIGN\n    std::cout << "MULTIPLE ROW SAMPLE"

but this isn't working for me.

A possible input:

some program code SAMPLE_SIGN text inside the 
sample SAMPLE_SIGN

What is the correct version for this?


Solution

  • if you want to allow it in any position of the row, not only the begining then shouldn't use ^ and allow your sign: SAMPLE_SIGN or:| end of line:\n and after this can be anything *

    "SAMPLE_SIGN"([^SAMPLE_SIGN]|\n)*"SAMPLE_SIGN"  std::cout << "Block"
    

    This will allow you to use SAMPLE_SIGN as first character inside a block of SAMPLE_SIGN and. As a primitive comment section for example.