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

3 Answers 3

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"-]+) 
Sign up to request clarification or add additional context in comments.

5 Comments

Is there no other option? I dont like lookaheads they take to much CPU power on large and many files,
@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.
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?
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 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 :)
0

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

Comments

0

You can try negative lookarounds:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.