How to detect blocks of text

320 Views Asked by At

Is it possible to get block of text inbetween two markers? I am trying to write my version of LOLCODE and i want to make if statement - then i ran into this problem.

Basic thing is, that i want to do this:

IS #DIR = 5
    YUP
 -if statement suceeded, execute code here-
    NOPE
 -if statement returned false, execute code here
BYE

Explanation: This code should check if variable #DIR is equal to five, if yes then execute code in YUP block, if not - execute code in NOPE block.

My question is : How to read this from text file and execute proper block of code using java?

1

There are 1 best solutions below

4
On

Try a regular expression like this:

searchText.matches("^\\s*IS\\s+(#\\w+)\\s*=\\s*(\\w+)\\s*")

This expression only evaluates The first line "IS #DIR = 5" but you can complete it is only the idea to do it ;)

Edit: Maybe this link can help you if the inner blocks of code are Java: Dynamic code execution