English 中文(简体)
Javascript 替换未逃避的斜线
原标题:Javascript replace unescaped slash

我想用反斜线取代一条绳子上的一条未逃脱的斜线。

"contenthsgjhome.css".replace(/\/gi,"/")

返回“contenthsgjhome.cs.cs”。我理解,如果将其修改为

"\content\hs\gj\home.css".replace(/\/gi,"/")`

然后它就会像预期的那样工作, 但我无法更改字符串, 因为它只是nordejs path.join ("conetnt,"hs","gj","hh.cs") 的输出 。

我该怎么办?

最佳回答

The reason it is returning "contenthsgjhome.css" is that your string doesn t really have any backslashes in it at all because single backslashes in a string literal will be ignored unless they make sense to escape the following character (e.g., "\" or " "). "c" has no special meaning as an escape so it is interpreted as "c".

"contenthsgjhome.css"

结局与:

"contenthsgjhome.css"

因此, . replace () 找不到反斜线 。

(请注意,如果您 do 以字串字串形式(如 \\" ,该字串仅是字面语法的一部分,一旦被解释,所产生的字符串只有一个反斜线 ""),则该字串的反斜线(注意) 。)

或许你可以解释一下你所说的“只是FS的产出”的意思。当JSP/ASP/PHP/etc 输出JS代码时,这是一个常见的问题 — — 在JSP/ASP/PHP/etc 代码中,逃跑需要在JSP/ASP/PHP/etc 代码中发生,然后再由JSP/ASP/PHP/etc 的翻译看到。

问题回答
yourstring.split(String.fromCharCode(92)).join( / )




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签