久久久久久久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)
主站蜘蛛池模板: 神马久久久久久久久久 | 91天堂网 | 亚洲精品在线免费观看视频 | 日韩视频一区二区 | 午夜日韩视频 | 日日夜夜操天天干 | 国产91在线 | 亚洲 | 一区二区日韩 | 夜夜骑首页 | 成人网av | 亚洲欧美日本在线 | 国产四区 | 亚洲综合色视频在线观看 | 91 在线| 免费在线一区二区三区 | 精品国产一区二区三区av片 | 一区二区三区精品视频 | 久久99精品久久久久久国产越南 | 欧美a∨| 色性av | 久久久久久亚洲精品 | 亚洲国产aⅴ精品 | 日韩一区中文字幕 | 亚洲国产中文字幕 | 最新国产精品视频 | 七七婷婷婷婷精品国产 | 亚洲高清一区二区三区 | 国产偷录视频叫床高潮对白 | 美女爽到呻吟久久久久 | 欧美一区中文字幕 | 欧美一级视频免费看 | 国产福利在线播放 | 国产欧美精品区一区二区三区 | 毛片免费看 | 成人午夜免费在线视频 | 午夜网 | 一区二区三区网站 | 亚洲精品在线视频 | 亚洲欧美视频 | 欧美嘿咻| 特级特黄特色的免费大片 |