除了一个特定的单词,用javascript替换所有单词

时间:2016-08-03 20:11:50

标签: javascript

我希望在"之前替换包括"在内的所有单词。除了一个特定的词,包括"之前" (不区分大小写)

示例:"之前" ="之后“;除了" beforethree"

之前两次之前三次之前

结果应该是:

在三人之后完成之后

我的代码是:

  <script>
function Replace() {
    var str = document.getElementById("id").innerHTML; 
var res = str.replace(/before/gi, "after");
    document.getElementById("id").innerHTML = res;
}
</script>

提前非常感谢你们!

3 个答案:

答案 0 :(得分:4)

您可以使用negative lookahead正则表达式:

public HttpResponseMessage Getdetails([FromUri] string[] id)
{
    string connStr = ConfigurationManager.ConnectionStrings["ProDataConnection"].ConnectionString;
    using (OracleConnection dbconn = new OracleConnection(connStr))
    {
         var inconditions = id.Distinct().ToArray();
         var srtcon = string.Join(",", inconditions);
         DataSet userDataset = new DataSet();
         var strQuery = @"SELECT * from STCD_PRIO_CATEGORY where STPR_STUDY.STD_REF IN(" + srtcon + ")";
         using (OracleCommand selectCommand = new OracleCommand(strQuery, dbconn))
         {
              using (OracleDataAdapter adapter = new OracleDataAdapter(selectCommand))
             {
                 DataTable selectResults = new DataTable();
                 adapter.Fill(selectResults);
                 var returnObject = new { data = selectResults };
                 var response = Request.CreateResponse(HttpStatusCode.OK, returnObject, MediaTypeHeaderValue.Parse("application/json"));
                 ContentDispositionHeaderValue contentDisposition = null;

                 if (ContentDispositionHeaderValue.TryParse("inline; filename=ProvantisStudyData.json", out contentDisposition))
                {
                     response.Content.Headers.ContentDisposition = contentDisposition;
                }

                return response;
            }
        }
    }
}

答案 1 :(得分:0)

一个选项是

  1. beforethree替换为%%three
  2. 之类的安全内容
  3. before替换为after
  4. %%替换为before
  5. 我确定那里有更优雅的解决方案

答案 2 :(得分:0)

将您的替换修改为

override func awakeFromNib() {
        let myPath = PocketSVG.pathFromSVGFileNamed("").takeUnretainedValue()

        let myShapeLayer = CAShapeLayer()
        myShapeLayer.path = myPath

        myShapeLayer.strokeColor = UIColor.redColor().CGColor
        myShapeLayer.lineWidth = 3
        myShapeLayer.fillColor = UIColor.whiteColor().CGColor

        self.layer.addSublayer(myShapeLayer)
    }