I have a problem with finding a regex pattern that should match any text containing a group of letters, and in the same time it does not contain another group of letters.
Iterating a file line by line, I need to extract the lines containing the word 'input', AND not containing the word 'type'.
So, 'input damian whatever' is a match, while 'input damian type whatever' is not.
So why Regular expression is required?
As you know the exact text which you need so try this.
Ioan Damian Sirbu
Joined: Dec 22, 2008
I was giving an arbitrary example.
The concrete situation is:
- I need to make a search in Eclipse in all files.
- I need to find the files that contain a custom tag that is like this <input type="calendar"> but is not like <input type="calendar" theme="simple">
I think that using Eclipse's regex matches are an option, and in the same time this regex dilemma is interesting by itself
No, it was my fault.. I posted wrong.
By matching (.*document.*), I was capturing the whole expression. If the input was "calendar simple", the
lookahead (.*simple.*) would have nothing left to match.
The correct pattern would be (calendar)(?!.*simple.*). This would return true for "calendar" or 'calendar some words", but false for "calendar simple".
I tested this with the RegexTestHarness in the Sun tutorials.
PS: Now that I think I got how this works, I am trying to combine lookahead with lookbehind