正则表达式替换字符串(smarty)
Regex replace from a string ( smarty)
我正在尝试用空 space("") 替换特定字符(冒号)后的字符串 ":"
示例:2017 - Alpha Romeo United kingdom : New vehicle (by abc)
我想输出为“2017 - Alpha Romeo United kingdom
”
如果有人能帮我用 smarty 写正则表达式,我将不胜感激
非常感谢
您可以使用以下 regex (使用 capturing group and positive lookahead) :
input >> 2017 - Alpha Romeo United kingdom : New vehicle (by abc)
regex search >> (?=:):(.*)
replace with >> " "
output >> 2017 - Alpha Romeo United kingdom
聪明
{
assign
var = "articleTitle"
value = "2017 - Alpha Romeo United kingdom : New vehicle (by abc)"
} {
$articleTitle | regex_replace: "/(?=:):(.*)/": " "
}
private void Form1_Load(object sender, EventArgs e)
{
string str = "2017 - Alpha Romeo United kingdom : New vehicle (by abc)";
str = Regex.Replace(str, @":+(.*)", "");
MessageBox.Show(str);
}
我正在尝试用空 space("") 替换特定字符(冒号)后的字符串 ":"
示例:2017 - Alpha Romeo United kingdom : New vehicle (by abc)
我想输出为“2017 - Alpha Romeo United kingdom
”
如果有人能帮我用 smarty 写正则表达式,我将不胜感激
非常感谢
您可以使用以下 regex (使用 capturing group and positive lookahead) :
input >> 2017 - Alpha Romeo United kingdom : New vehicle (by abc)
regex search >> (?=:):(.*)
replace with >> " "
output >> 2017 - Alpha Romeo United kingdom
聪明
{
assign
var = "articleTitle"
value = "2017 - Alpha Romeo United kingdom : New vehicle (by abc)"
} {
$articleTitle | regex_replace: "/(?=:):(.*)/": " "
}
private void Form1_Load(object sender, EventArgs e)
{
string str = "2017 - Alpha Romeo United kingdom : New vehicle (by abc)";
str = Regex.Replace(str, @":+(.*)", "");
MessageBox.Show(str);
}