It is necessary regexp to replace in a line of a colon with blanks, excepting situations where a colon the first and (or) last symbol - them is simply deleted.
Example1
"6:206:НР"
-> "6 206 НР"
Example2
":206:"
-> "206"
It is necessary regexp to replace in a line of a colon with blanks, excepting situations where a colon the first and (or) last symbol - them is simply deleted.
Example1
"6:206:НР"
-> "6 206 НР"
Example2
":206:"
-> "206"
You can't do conditional replacement with a single regex alone. You'll need to use your language's library. Python example:
s = s.replace(':', ' ').strip()
If you absolutely need to do it through regex, you can use two of them. Example:
s = re.sub(':', ' ', re.sub('^:|:$', '', s))
In PHP you can do:
$from = array('/^:|:$/','/:/');
$to = array('',' ');
$output = preg_replace($from,$to,$input);
It's hardly necessary to use regular expressions for such a trivial task. Replace all colons with spaces first, then trim the resulting string to get rid of spaces before and after the data.
PHP Syntax:
$string = trim(str_replace(':', ' ', $string));