0

I am attempting to match #if macro do #end from the following:

class OtherClass {}
class MyClass<T:{T_1,T_2}> #if macro do #end {}

<T:{T_1,T_2}> illustrates the character set inbetween the string class and #if macro do #end

The problem is, if you use the dot or an applicable character set, you are going to match from OtherClass. So presumably something like this is in order:

(.(?!class))+?)

I haven't seen something like this widely discussed. It matches on a test case, but it appears to cause a pcre_exec error on content that it doesn't actually match. Perhaps there is a lot of backtracking going on. Any suggestions on how to resolve this assuming that an applicable character set [a-zA-Z0-9_,\.{}<>] would in fact match from a previous class declaration. Let us presume that it is not possible to solve this with character limit hacks.

MetaChrome
  • 3,210
  • 6
  • 31
  • 48
  • http://stackoverflow.com/questions/406230/regular-expression-to-match-string-not-containing-a-word?rq=1 This is discussed there and it is as I presumed. However, please answer as to why it would possibly cause an error. – MetaChrome Jul 25 '13 at 03:24
  • I find your description very unclear and confusing. I have no idea what you're asking. I can't figure out what you mean by "illustrates the character set inbetween the string class and #if macro do #end", or "intermittent characters don't contain matched string", or "if you use the dot or an applicable character set, you are going to match from OtherClass". The regex `#if macro do #end` matches "#if macro do #end". Obviously that's not what you mean, but that answers the question as you asked it. You need to be a lot clearer about what you're trying to accomplish. – Adi Inbar Jul 25 '13 at 04:47
  • ...I have specified in full the parameters of the problem. ```class(.*?)#if macro do #end``` is going to match from the first class, which is the problem. The phrase ```applicable character set``` is used in the context of disqualifying a proposed solution of a more narrow character set than ```.``` because no such set exists to resolve the issue (said character set would in fact still match from the first ```class```). – MetaChrome Jul 25 '13 at 05:42
  • Good luck finding anyone who can decipher what you're talking about. I have no idea what you just said, it was even more unclear and confusing than the original question. You know what you have in mind, what you mean by the vague terminology you're using, and what you intend for things to represent, but others can only go by your words. If you want anyone to be able to help you, you'll need to be less "clever" and more clear. – Adi Inbar Jul 25 '13 at 07:03
  • Thanks for reading your attempted help. The posted discussion resolves the general problem. The problem in this instance was with a dependent pcre library (which one, I am not aware) and was resolved by doing ((?:(?!class).)+?), declaring the repeating group a non-reference group. You can see the practical application of this regex here: http://gskinner.com/RegExr/?35n4j – MetaChrome Jul 25 '13 at 07:58

0 Answers0