We have dynamic text which may contain below type of Data.
Starting Identifier keyword : block
End Identifier keyword : #blockend
We have to remove below -
a) 2 lines which contains above 2 keywords
b) Opening and closure of round brackets. Round bracket will start from next line of the keyword ‘block’ and end in the same line/1 line before which contains the keyword ‘#blockend’.
Input String -
‘’’ Block Questions
SPAB “” block fields
(
SP1 "How old are you?<br/><span class='none' numerickeypad='true'></span><span class='mrInstruct'>(Please enter your exact age below.)</span>"
style(
Width = "3em"
)
long [18 .. 65];
SP2 "Have you seen this ad on TV/at the cinema before today?"
[
metatype = "rowpicker",
grid$all$width = 100,
row$all$center = false,
row$hovercolor = "#aadeee"
]
categorical [1..1]
{
_1 "No, this is the first time",
_2 "Once or twice",
_3 "A few times",
_4 "Lots of times"
};
SP3"You have completed the survey. Thank you for your time."
info;
);
'#blockend
Output String -
SP1 “How old are you? (Please enter your exact age below.)”
style(
Width = “3em”
)
long [18 … 65];
SP2 "Have you seen this ad on TV/at the cinema before today?"
[
metatype = "rowpicker",
grid$all$width = 100,
row$all$center = false,
row$hovercolor = "#aadeee"
]
categorical [1..1]
{
_1 "No, this is the first time",
_2 "Once or twice",
_3 "A few times",
_4 "Lots of times"
};
SP3"You have completed the survey. Thank you for your time."
info;
@prasath17 … block is there at the second line of the input string. it is ‘block’ in small letters (before the keyword ‘fields’).
Need to delete the entire line containing the keywords ‘block’ and ‘#blockend’.
Also need to remove opening round bracket (will be there in the next line of keyword ‘fields’) and closure of round brackets (will be the same line/one line above of the keyword ‘#blockend’).
@prasath17 …SP1, SP2, SP3 etc. will be carrying different types of data. Some may contain table data, some will carry other types of data. Only thing fix is that starting keyword ‘block’ and end keyword ‘#blockend’.
@prasath17 … The pattern is working fine for the input which I mentioned here.
But the problem is - since the content inside both the rounded brackets will be dynamic, so I tried testing by altering the sequence of SP1 and SP2 :: it failed there.
Is it possible to get such pattern which will be able to remove only 4 lines (block, round bracket opening, round bracket close, #blockend) and keep the dynamic content inside it intact?
@prasath17 … If we consider the 1st part of the match, say for example from the input provided, if we would like to fetch -
SPAB “” block fields
(
Can we build any regex to match such pattern? Please consider the keyword ‘fields’ sometimes can be 1/2 lines below of the keyword ‘block’ as well. But start of round brackets will always be the next line of keyword ‘fields’.
@prasath17 … let me elaborate you… from the above input my main purpose is to -
a) Delete the line containing keyword ‘block’.
b) 2 lines containing opening and terminating round brackets. Round brackets will always start in the next line of keyword ‘fields’ and it will always terminate in the line containing keyword '#blockend.
So, if we consider the Input String as -
‘’’ Block Questions
SPAB “” block fields
(
SP1 "How old are you?<br/><span class='none' numerickeypad='true'></span><span class='mrInstruct'>(Please enter your exact age below.)</span>"
style(
Width = "3em"
)
long [18 .. 65];
SP2 "Have you seen this ad on TV/at the cinema before today?"
[
metatype = "rowpicker",
grid$all$width = 100,
row$all$center = false,
row$hovercolor = "#aadeee"
]
categorical [1..1]
{
_1 "No, this is the first time",
_2 "Once or twice",
_3 "A few times",
_4 "Lots of times"
};
SP3"You have completed the survey. Thank you for your time."
info;
); '#blockend
Expected Output is -
SP1 "How old are you?<br/><span class='none' numerickeypad='true'></span><span class='mrInstruct'>(Please enter your exact age below.)</span>"
style(
Width = "3em"
)
long [18 .. 65];
SP2 "Have you seen this ad on TV/at the cinema before today?"
[
metatype = "rowpicker",
grid$all$width = 100,
row$all$center = false,
row$hovercolor = "#aadeee"
]
categorical [1..1]
{
_1 "No, this is the first time",
_2 "Once or twice",
_3 "A few times",
_4 "Lots of times"
};
SP3"You have completed the survey. Thank you for your time."
info;
Idea is to Ignore what starts before any questions…Since all the questions starting with SP* followed by #, I started my pattern with that which automatically deleted the first 3 lines …
@prasath17 … issue here is, all the time question won’t start with SP*. It may be of any pattern in-between those rounded brackets.
Only things constant here is -
a) keyword ‘block’
b) line contains start of rounded brackets (next line of ‘fields’)
c) line contains closure of rounded brackets (same line in keyword #blockend)
@DewanjeeS – I know you are looking for a keyword before the question… By my point, how many different types of questions you are having…I saw qQ, like this there should only few right?? Here you go…