REGEX for string substitution to replace semicolon with space + semicolon
You didn’t specify which language you are using for your regex so I took the liberty of writing a small script in Perl to do this:
$text = "Name;Age;Location;Gender Ram;39;India;Male Jeni;23;China;Female";
print "$textn";
$semicolon = 0;
for $i (0..length($text)-1)
{
$char = substr($text, $i, 1);
if($char =~ ";")
{
$semicolon++;
}
if($semicolon == 2)
{
substr($text, $i, 0) = ' ';
$semicolon = -2;
}
}
print $text
The important bits are the for loop that iterates the string $text
and the substr()
function which inserts whitespace whenever a second semicolon is detected. The only string matching that is actually done is the $char =~ ";"
line which checks for the semicolon.
Read more here: Source link