I need to get information on variables and the only thing I have is the variable name. In this case let’s say I need to get the chunk that belongs to SOME_LARGE_VARIABLE (every chunck starts with <0> and ends with <0>)
In other words how can I get the chunk <0>....SOME_LARGE_VARIABLE.....<0>
Note I do not want to have <0> ...... <0> ..... SOME_LARGE_VARIABLE .... <0>
<0>
temp
<0>
fo0
<0>
BLA BLA BLA
kjfsd
foodskjdsf
kj
<0>
someVariable
<0>
SOME_LARGE_VARIABLE
<0>
So far I have tried:
<0>[\s\S]*?SOME_LARGE_VARIABLE[\s\S]*?<0>
that finds <0> and then continues until it finds SOME_LARGE_VARIABLE and stops until <0>
note that will select everything
my temporary solution is:
<0>[\s\S]{1,25}SOME_LARGE_VARIABLE[\s\S]*?<0>
this restricts the selection to less than 25 characters. I think this is to risky because there might be two chuncks smaller than 25 characters
EDIT
In other words I want to end up with:
<0>
SOME_LARGE_VARIABLE
<0>
and the only thing I have is SOME_LARGE_VARIABLE knowing that every chunk starts and ends with <0>
Instead of using
.*?you could use(?:(?!<0>).)*, like so:But you might as well be better off splitting the string on
<0>and checking which parts matchSOME_LARGE_VARIABLE.Note that the expression will never match the second “chunk” in:
Because the second
<0>is consumed by the expression, not allowing it to match. (The splitting approach does not have this problem.)You can fix that by using a lookahead tho:
If you want
.to match line breaks as well, add(?s)in the beginning of the expression, like so: