Why do you want to use regexes for that?
($before, $after) = split(/$middle\.$middle/, $line);
And then use $before
and $after
each once without and once with $middle
concatenated to the end and start of the string respectively.
Question
Say, I have lines like:
SOMETHING.AA.AA.DARKSIDE BLaH.AA.AA.Blah
I want to find for each line $before = $1; $after = $2; of the $middle = ”AA” Such that for example for line 1 I get:
$before= “SOMETHING.”
$After = “.AA.DARKSIDE”
And also
$before= “SOMETHING.AA”
$After = “.DARKSIDE”
My code looks like this:
$middle = “AA”;
foreach (@lines){
$line = $_;
while ($line =~m/^(.+)$middle(.+)$/g){
$before = $1;
$after = $2;
}
}
Is there a simple way to change regex in my while?
PS: $middle
will be a variable so i cannot hardcode it.
Thank you for help.
Solution
Why do you want to use regexes for that?
($before, $after) = split(/$middle\.$middle/, $line);
And then use $before
and $after
each once without and once with $middle
concatenated to the end and start of the string respectively.