正则匹配注解(用正则表达式在java怎么去匹配注释 //的单行注释 /*单行注释*/ /* *多行注释 */)
本文目录
- 用正则表达式在java怎么去匹配注释 //的单行注释 /*单行注释*/ /* *多行注释 */
- 如何用正则表达式来匹配c语言风格的注释
- 求js正则匹配注释,包括多行注释和单行注释
- php怎么正则匹配js的多行注释并删除多行注释
- 求个正则表达式能匹配这种注释
- 正则匹配注释
- vs2012 C++ 用正则表达式匹配代码中的块注释
- 如何用正则表达式 匹配注释语句,也就是/* */,其中可以有多的/*,不可以有多的*/,除非多出的*/被双引号括住.
用正则表达式在java怎么去匹配注释 //的单行注释 /*单行注释*/ /* *多行注释 */
先说结果:
我是测试出来了正则表达式,但是是针对三种注释,写了三种正则。
没有实现单一的正则表达式,支持所有的注释类型的。
代码你可以参考参考:
//单行注释
String commentsStr = "//this is single line comments";
Pattern singleLineCommentP = *****("^//.*?$");
Matcher foundSingleLineComment = *****(commentsStr);
boolean foundSingle = *****();
*****(foundSingleLineComment);
*****(foundSingle);
/*单行注释*/
String doubleStarCommentStr = "/* this is double star comments */";
Pattern doubleStarCommentP = *****("^/\\*.*?\\*/$");
Matcher foundDoubleStarComment = *****(doubleStarCommentStr);
boolean foundDouble = *****();
*****(foundDoubleStarComment);
*****(foundDouble);
/*
*多行注释
*/
String multiLineComments = "/* \n" +
"* this is \n" +
"* multi line comment \n" +
"*/";
Pattern multiLineCommentP = *****("^/\\*.*\\*/$", *****);
Matcher foundMultiLineComment = *****(multiLineComments);
boolean foundMulti = *****();
*****(foundMultiLineComment);
*****(foundMulti);
感兴趣的话,可以去看看我总结的:
crifan 正则表达式学习心得
(此处不给贴地址,请用google搜标题,即可找到帖子地址)
如何用正则表达式来匹配c语言风格的注释
C语言风格,只支持一种 就是/**/包含的
虽然现在C一样可以用//注释整行,不过这个不是C风格,而是C++风格,只是后来C也通用了。 (C99)
只考虑/**/
正则表达式如下
/\*(.|)*?\*/
求js正则匹配注释,包括多行注释和单行注释
你好,我写了一个正则可以满足你的需求
var rNote = /(\/\/.*$)|(\/\*(.|\s)*?\*\/)/g; // 匹配单行或多行注释
但是有个小瑕疵,就是会匹配到链接或带有’//’的字符串:
// 链接
***隐藏网址***
// 带有//的字符串
abskdak//asdljslad//sadajk
上面链接和字符串的’//’开始到行尾的内容也会被匹配,这里需要注意下
希望能解决你的问题,望采纳~
php怎么正则匹配js的多行注释并删除多行注释
获取文本内容file_get_contents(’****’);
正则匹配,前后截取
《?php
$str = ’aaaa/*123121321312312*/ccc’;
//$pattern = ’/^\/\*.*\*\/$/’;
$pattern = ’/\/\*.*\*\//’;
//preg_match($pattern, $str,$matches);
echo ’《pre》’;
var_dump(preg_replace($pattern, ’’, $str));exit;
如果想要获取注释内容,可以把我注释的两行代码打开。不打开注释就是直接删除掉了。
结果为:string(7) "aaaaccc"
求个正则表达式能匹配这种注释
你好,下面是一个python的例子代码:
import re
inputStr= “《!--这里是任意字符 --》”
hit=*****(r’(《--(+—》)’,inputStr)
if hit:
print(hit)
正则匹配注释
/\*\/(?:(?!\/\*).)*?(\’key\’=》\’.+?\’)/s 取group1
不过用的时候需要在待测字符串开头加上一对’/**/’,才不会有bug
vs2012 C++ 用正则表达式匹配代码中的块注释
字符串需要转义,不光是正则里的转,作为c++的字符串还要再转
regex rx2("/\\*(.|\r\n|\n)*?\\*/"); //我这\r\n没找到换行,反倒单独的\n能匹配
----------》
/* RC_INVOKED */
/* _QUEUE_ */
/*
* This file is derived from software bearing the following
* restricti***:
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this
* software and its documentation for any purpose is hereby
* granted without fee, provided that the above copyright notice
* appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation.
* Hewlett-Packard Company makes no representati*** about the
* suitability of this software for any purpose. It is provided
* "as is" without express or implied warranty.
*/
/*
* Copyright (c) 1992-2009 by ***. Plauger. ALL RIGHTS RESERVED.
* C***ult your license regarding permissi*** and restricti***.
*****:0009 */
如何用正则表达式 匹配注释语句,也就是/* */,其中可以有多的/*,不可以有多的*/,除非多出的*/被双引号括住.
给你写了个,不知道是不是这个效果:
\/\**?(?《!")\*\/(?!")
关键解释:
(?!“) 匹配后面跟的不是双引号的位置
(?《!") 匹配前面不是双引号的位置
PHP测试代码:
《?php
$str = 《《《EOT
/*
/* /* /* "*/"
*/
*/
EOT;
preg_match_all(’/\/\**?(?《!")\*\/(?!")/i’, $str, $matches);
print_r($matches);
?》
更多文章:
diverse中文意思(different的同义词有那些呢)
2026年5月5日 11:40
jquery对象可以调用dom种方法(怎么把jquery对象于document对象的相互转换)
2026年5月5日 11:20
oracle游标(oracle存储过程中打开游标有几种方法用open直接打开)
2026年5月5日 11:00
正则匹配注解(用正则表达式在java怎么去匹配注释 //的单行注释 /*单行注释*/ /* *多行注释 */)
2026年5月5日 10:40
将一串字符串存到数组(C语言里如何把一个字符串存在一个数组里)
2026年5月5日 10:20





