1

我使用 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"

我已经尝试过这个(读取不以序列开头的字符串的正则表达式),但对我不起作用:

^(?! \*/\t).+".*"

有什么帮助吗?

编辑:我用过:

^(?!#| |(\t*/)|(/)).+".*"

它返回:

put_str("Text inside"

我快要找到解决方案了。

4

3 回答 3

1

EditPad显然在pro 版本 6lite 版本 7中支持可变长度的lookbehind ,因为它的风格被指示为“JGsoft”Just Great Software 正则表达式引擎

知道这一点并且不使用捕获组,您可以组合两个可变长度的lookbehinds

(?<!^[ \t]*/?[*#][^"\n]*")(?<=^[^"\n]*")[^"]+
  • (?<!^[ \t]*/?[*#][^"\n]*")避免引用部分前面有任何评论的负面回顾,[ \t]*/?[*#]评论前面可以有任何数量的空格/制表符。设为/可选,因为多行注释也可以以*.
  • (?<=^[^"\n]*")肯定的向后看,以确保有任何数量的[^"\n]characters, that are no quotes or newlines然后是之前的一个报价。
  • [^"]+由于应该总是平衡引用,现在应该很方便,匹配第non-quotes一个之后double-quote(在后面的后面)
  • 如果单行"可能出现在任何一行(不平衡),将 end:[^"]+改为[^"\n]+(?=")

在此处输入图像描述

对于这个问题,可能有不同的解决方案。希望能帮助到你 :)

于 2014-09-03T22:11:20.507 回答
0

您可以使用此正则表达式:

/\*.*\*/(*SKIP)(*FAIL)|".*?"

工作演示

在此处输入图像描述

编辑:如果你使用 EditPad 那么你可以使用这个正则表达式:

"[\w\s]+"(?!.*\*/)
于 2014-09-03T19:32:44.850 回答
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
于 2014-09-03T19:47:48.817 回答