久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

類型為//的干凈 JavaScript 注釋的正則表達式

Regular expression for clean javascript comments of type //(類型為//的干凈 JavaScript 注釋的正則表達式)
本文介紹了類型為//的干凈 JavaScript 注釋的正則表達式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在使用以下 REGEXP:

I′m using the following REGEXP:

$output = preg_replace( "http:///(.*)\n/", "", $output );

代碼運行良好但是!!!!,當 URL 像 (http://this_is_not_a_comment.com/kickme) 時,代碼會替換它... (http://)

The code works well BUT!!!!, when a URL like (http://this_is_not_a_comment.com/kickme), the code replaces it... (http://)

你能做些什么來不替換這些 URL.

What can you do to no replace that URLs.

謝謝,

推薦答案

您需要一個可以區分代碼和注釋的正則表達式.特別是,由于//的序列既可以在字符串中,也可以在注釋中,因此只需區分字符串和注釋即可.

You need a regular expression that can distinguish between the code and the comments. In particular, since the sequence of // can either be in a string or a comment, you just need to distinguish between strings and comments.

這是一個可能會執行此操作的示例:

Here’s an example that might do this:

/(?:([^/"']+|/*(?:[^*]|*+[^*/])**+/|"(?:[^"\]|\.)*"|'(?:[^'\]|\.)*')|//.*)/

在替換函數中使用它,同時用第一個子模式的匹配替換匹配的字符串,然后應該能夠刪除 // 樣式注釋.

Using this in a replace function while replacing the matched string with the match of the first subpattern should then be able to remove the // style comments.

一些解釋:

  • [^/"']+ 匹配任何不是注釋開頭的字符(//…>/*...*/) 或一個字符串
  • /*(?:[^*]|*+[^*/])**+/ 匹配 /* ...*/ 樣式注釋
  • "(?:[^"\]|\.)*" 匹配雙引號中的字符串
  • '(?:[^'\]|\.)*' 匹配單引號中的字符串
  • //.* 最終匹配 //... 樣式注釋.
  • [^/"']+ matches any character that is not the begin of a comment (both //… and /*…*/) or of a string
  • /*(?:[^*]|*+[^*/])**+/ matches the /* … */ style comments
  • "(?:[^"\]|\.)*" matches a string in double quotes
  • '(?:[^'\]|\.)*' matches a string in single quotes
  • //.* finally matches the //… style comments.

由于前三個結構被分組在一個捕獲組中,匹配的字符串可用并且當用第一個子模式的匹配替換匹配的字符串時沒有任何改變.僅當 //... 樣式的注釋匹配時,第一個子模式的匹配項為空,因此它被替換為空字符串.

As the first three constructs are grouped in a capturing group, the matched string is available and nothing is changed when replacing the matched string with the match of the first subpattern. Only if a //… style comment is matched the match of the first subpattern is empty and thus it’s replaced by an empty string.

但請注意,這可能會失敗.我不太確定它是否適用于任何輸入.

But note that this may fail. I’m not quite sure if it works for any input.

這篇關于類型為//的干凈 JavaScript 注釋的正則表達式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 精品国产青草久久久久96 | 国产在线观看一区二区三区 | 免费毛片在线 | 日本理论片好看理论片 | 日日干日日 | 美女一区二区在线观看 | 日韩在线一区二区三区 | 日韩a v在线免费观看 | 一级欧美 | 国产探花在线精品一区二区 | 夜夜夜夜夜夜曰天天天 | yiren22 亚洲综合 | 波多野结衣精品在线 | 一区二区免费 | 精品久久国产 | 日本a视频 | 99亚洲 | 一级a性色生活片久久毛片 一级特黄a大片 | 午夜精品一区二区三区在线播放 | 国产女人精品视频 | 精品一二三 | 日韩欧美电影在线 | 日韩欧美一区二区三区免费观看 | 久久精品国产一区 | 国产日韩电影 | 中文字幕男人的天堂 | 天天操,夜夜爽 | 中文字幕不卡一区 | 欧美国产一区二区 | 亚洲欧美中文字幕在线观看 | 伊人艹| 干干干操操操 | 97超级碰碰 | 国产精品久久一区 | 蜜桃在线一区二区三区 | 在线播放第一页 | 成人三级在线观看 | 国产精品视频 | 四虎国产 | 久久久久亚洲国产| 午夜精品一区二区三区三上悠亚 |