我使用EditPad Pro文本编辑器。 我需要将字符串读入代码,但我需要忽略以标签" / *"开头的字符串。或标签+ / *,例如:
/**
* Light up the dungeon using "claravoyance"
*
* memorizes all floor grids too.
**/
/** This function returns TRUE if a "line of sight" **/
#include "cave.h"
(tab here) /* Vertical "knights" */
if (g->multiple_objects) {
/* Get the "pile" feature instead */
k_ptr = &k_info[0];
}
put_str("Text inside", hgt - 1, (wid - COL_MAP) / 2);
/* More code*** */
我想回来:
"Text inside"
我试过这个(阅读Regular expression for a string that does not start with a sequence),但不适合我:
^(?! \*/\t).+".*"
任何帮助?
修改:我用过:
^(?!#| |(\t*/)|(/)).+".*"
它回归:
put_str("Text inside"
我接近找到解决方案。
答案 0 :(得分:1)
EditPad显然支持专业版6 中的variable-length lookbehind和精简版7 ,因为它是flavor is indicated as "JGsoft":{ {3}}
了解这一点并且不使用Just Great Software regular expression engine,您可以组合两个可变长度capture groups:
(?<!^[ \t]*/?[*#][^"\n]*")(?<=^[^"\n]*")[^"]+
(?<!^[ \t]*/?[*#][^"\n]*")
避免引用部分前面带有[ \t]*/?[*#]
任何评论的负面观察,可以在任意数量的空格/制表符之前。将/
作为可选项,因为多行注释也可以从*
开始。(?<=^[^"\n]*")
保证的正面看法,即[^"\n]
,characters, that are no quotes or newlines
之前的任何数量,然后是一个引用。[^"]+
因为应该总是平衡引用,现在应该很方便,在第一个non-quotes
之后匹配double-quote
(在看后面)"
,请将结束时更改为:[^"]+
为[^"\n]+(?=")
可能存在针对该问题的不同解决方案。希望它有所帮助:)
答案 1 :(得分:0)
您可以使用此正则表达式:
/\*.*\*/(*SKIP)(*FAIL)|".*?"
<强> Working demo 强>
编辑:如果您使用EditPad,那么您可以使用此正则表达式:
"[\w\s]+"(?!.*\*/)
答案 2 :(得分:0)
以下是一种方法:^(?!\t*/\*).*?"(.+?)"
故障:
^(?!\t*/\*) This is a negative lookahead anchored to the beginning of the line,
to ensure that there is no `/*` at the beginning (with or
without tabs)
.*?" Next is any amount of characters, up to a double-quote. It's lazy
so it stops at the first quote
(.+?)" This is the capture group for everything between the quotes, again
lazy so it doesn't slurp other quotes