1

I have this currently

([\w\-"]+)[ ]+OBJECT-TYPE[^[::=]*]*::=[ ]*\{[ ]*([\w\-"]+) ([\w\-"]+)

What it does is search for stuff like this:

DATA1 OBJECT-TYPE
SYNTAX SEQUENCE OF ContactInfoEntry
MAX-ACCESS not-accessible
STATUS current
DESCRIPTION
"A table containing Contact Info information"
::= { DATA2  DATA3 }

I just had one problem that thought i fixed

OBJECT-TYPE[^[::=]*]*::=

This was meant to search for any chars after the string "OBJECT-TYPE" that wasnt "::=" until it actualy found "::=" this worked well until i noticed that

[^[::=]*]* 

actualy meant meant : or = and not the excact string "::=" so how do i fix that?

EDIT: If someone is still here so that i dont need to open another question, how do i ignore any and all chars, symbols, numbers, etc between two ".
Example:
dont ignore this "ignore everything that is in here" dont ignore again "ignore again" etc

Vajura
  • 1,112
  • 7
  • 16

3 Answers3

2

You can use a negative lookahead in this kind of construct:

(?:(?!::=).)*

To match any character except ::=.


By the way, [^[::=]*]* will match any character(s) except [, :, =, ] and then 0 or more ].


For the second part, you can use something like this, with some simplification applied:

([\w"-]+)[ ]+OBJECT-TYPE(?:"[^"]*"|(?!::=).)*::=[ ]*{[ ]*([\w"-]+) ([\w"-]+)
Jerry
  • 70,495
  • 13
  • 100
  • 144
  • Is there no other option? I dont like lookaheads they take to much CPU power on large and many files, – Vajura Jul 17 '14 at 12:58
  • @Vajura I don't like them much either, but no, it would be much much more complex if you use negated classes. You might search 'alternative for negative lookahead', the first one I get is [this](http://stackoverflow.com/a/1537425/1578604). – Jerry Jul 17 '14 at 13:02
  • Can you define what you mean by "ignore" and "don't ignore"? Regex is about matching and not matching... Maybe you mean to say that `::=` between quotes should not be treated as true `::=`, sort of like a comment? – Jerry Jul 17 '14 at 13:03
  • Oh yea sorry bad wording, i just meant that everything between commas should be match for the regex expression and yea as you said it should not be treated as a true ::= – Vajura Jul 18 '14 at 05:25
  • @Vajura Ok, I'm not sure where exactly you want this behaviour, but I have edited my answer so that things within quotes after `OBJECT-TYPE` are 'ignored'. Let me know whether that works for you or not :) – Jerry Jul 18 '14 at 05:36
0

Try with (:|=) that will pick one or the other. Not sure if you need to escape : or = though.

Rodrigo
  • 234
  • 1
  • 6
0

You can try negative lookarounds:

^((?!::=).)*

Pradeep Kumar
  • 6,836
  • 4
  • 21
  • 47