Regex between words

Asked

Viewed 243 times

3

I’m trying to make an appointment Regex return to me in a source code file statements that are not public %%Enum Tipo, but I’m not very familiar with Regex and I’m having a little trouble, someone has some hint on how to do this.

Basically this Regex would have to return me the statements:

public int Tipo
public int16 Tipo

that is, all that the type does not end with Enum as an example:

public CaixaTipoEnum Tipo
  • 1

    it’s hard to understand what you want and what’s going on. Rewrite the question using punctuation and code formatting.

  • I don’t usually wear it either RegEx. Just to give you a hint, it is already possible to find what you want semantically that is much better. Of course it’s not the simplest way, you need to learn a more complex API, but if that’s not all you need, this tool can be useful: https://roslyn.codeplex.com/

2 answers

3


You can use the following expression ^(public|private)((?!Enum).)*$.

I used a regular expression tester online Click here,

paste the expression there and you can test.

  • I was going to edit my answer to something similar (^((?!Enum).)*$) after seeing this answer in the OS, but you arrived first. Keep my +1 :)

  • heheh.. was the same answer I found, only incremented in expression the part (public|private), I saw in your reply! :)

  • So, using the expression (^((?!Enum).)*$) how do I edit it that after the Enum have the term Tipo

  • You want to take the expressions that contain the Type after the Enum? public CaixaTipoEnum Tipo that’s it?

  • @Pablovargas exchange Enum for (Enum.*Tipo).

1

Brute force never failed me.

First you take all member statements with the expression:

(public|private) .+?;

Put that on a list. Then, on the list, you take the ones you nay either with the expression:

Enum

Yes, just like that.

Now just take all the elements that are part of the first list, but that are not part of the second ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.