1

I use EditPad Pro text editor. I need read string into code, but I need to ignore ones that start with the label "/*" or tab + /*, for example:

/**
 * 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*** */

I like to return:

"Text inside"

I have try this (reading Regular expression for a string that does not start with a sequence), but not work for me:

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

any help?

Edit: I used:

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

And it return:

put_str("Text inside"

I'm close to finding the solution.

Community
  • 1
  • 1
Hernaldo Gonzalez
  • 1,977
  • 1
  • 21
  • 32

3 Answers3

1

EditPad obviously supports variable-length lookbehind in pro version 6 and lite version 7 since it's flavor is indicated as "JGsoft": Just Great Software regular expression engine.

Knowing this and without the use of capture groups, you could combine two variable length lookbehinds:

(?<!^[ \t]*/?[*#][^"\n]*")(?<=^[^"\n]*")[^"]+
  • (?<!^[ \t]*/?[*#][^"\n]*") The negative lookbehind for avoiding the quoted part to be preceded by [ \t]*/?[*#] any comments, which could be preceded by any amount of space/tab. Made the / optional, as a multi-line comment can also start with *.
  • (?<=^[^"\n]*") The positive lookbehind for assuring, that there's any amount of [^"\n], characters, that are no quotes or newlines followed by one quote before.
  • [^"]+ As supposed to be always balanced quoting, now it should be convenient, to match the non-quotes after the first double-quote (which is inside the lookbehind)
  • If a single " may occur in any line (not balanced), change the end: [^"]+ to [^"\n]+(?=")

enter image description here

Possibly there are different solutions for the problem. Hope it helps :)

Jonny 5
  • 12,171
  • 2
  • 25
  • 42
  • Almost!! I forgot include the code: #include "cave.h", and your solution show me "cave.h", can improve the regexp? – Hernaldo Gonzalez Sep 04 '14 at 13:19
  • @HernaldoGonzalez So also lines starting with `#` (with optional spaces preceded) should not be taken into account? See updated answer. – Jonny 5 Sep 04 '14 at 13:22
  • @HernaldoGonzalez Thanks for the compliment, also learned new, while thinking of your regex problem :) Great it works out now! – Jonny 5 Sep 04 '14 at 13:50
0

You can use this regex:

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

Working demo

enter image description here

Edit: if you use EditPad then you can use this regex:

"[\w\s]+"(?!.*\*/)
Federico Piazza
  • 30,085
  • 15
  • 87
  • 123
0

Here's one approach: ^(?!\t*/\*).*?"(.+?)"

Breakdown:

^(?!\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
Brian Stephens
  • 5,161
  • 19
  • 25