Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular expression to find whether line DOES NOT end with a specific pattern

 
Kingsly Theodar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have list of directories and java files.

/usr/com

/usr/com/file1.java

/usr/com/file2.java

/usr/com/regexdir1

/usr/com/regexdir2

/usr/com/regexdir1/file3.java

/usr/com/regexdir2/file4.java

For selecting lines ending with ".java", I will use regular expression "*.java"

But for selecting list of directories, I am aware that I should select all the lines that does not match the pattern "*.java"

How will I express this in regular expression?

Any help on this is greatly appreciated. Please help.



Thanks,

T.Kingsly
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it fails that regular expression than you should know it is a directory.

You could easily just do

Eric
 
Kingsly Theodar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eric Pascarello,
That looks great.
But the tool I am using accepts only Regular expression.
Any idea of using regular expression for the same?

Thanks,
T.Kingsly
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like this?

.*[^\.java]

Eric
 
Kingsly Theodar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bingo. That is the one.

Thanks for sharing it Eric



Thanks,
T.Kingsly
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic