Gtranstic插件在撇号之前添加反斜杠

Gtranslate plugin add backslash before apostrophe

本文关键字:添加 插件 Gtranstic      更新时间:2023-09-26

我正在为客户端网站使用 Gtranslate 插件并使用撇号翻译一些单词,我发现该插件在其前面添加了反斜杠:

你好,我要去吃晚饭...

如何删除撇号前的反斜杠?

我可以将 php 修复添加到插件中,或者我应该使用 JavaScript 解决方案?

你能帮我找到一种在这两种情况下都做到这一点的好方法吗?

谢谢。

Javascript 中的正则表达式可以删除所有反斜杠,但在某些情况下,字符串可能真正意味着使用反斜杠。然后,您需要从''更改为'

http://jsfiddle.net/scx8t/

​s = "I'''m Bob and you'''re Jane'''''s mother";
document.write("before: " + s + "<br>")
s = s.replace(/''/g, "")​​​​​​​​​​​​​​​​​​​​​​​​​​;
​document.write("after: " + s);

专门替换 ''' 写s.replace(/'''/g, "'")

对于此斜杠/,您将编写s.replace(/'//g, ""),对于两者,s.replace(/['/'']/g, "")

编辑:对于此应用程序,PHP preg_replace似乎更合适。我现在只是没有运行PHP,所以我写了Javascript:P 下面是它应该的样子:

<?php
$str = 'I''''m Joe, you''''re Sara';
$str = preg_replace('/''/', '', $str);
// I'm not sure if the g goes at the end of the pattern to replace all.
echo $str;
?> 

注意 /''/可能需要/''/g。我不熟悉PHP。

从这里 示例 #4 带状空格