File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes using Regex Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "using Regex" Watch "using Regex" New topic

using Regex

ramesh akula

Joined: Mar 18, 2007
Posts: 1
i have one text document(*.txt) file it contains some rows and columns
my requirement is that i have to remove some rows in that file

for example : ( my text file contain the below data)
N10 X-10.256 Y23.675
N11 X-23.563 Y45.078
N12 X34.567
N13 Y-56.774
N14 X-34.876 Y-23.878 F100
i want to delete sequence numbers that is N10,N11,N12,N13,N14.
so using REGEX can we do something ???

please helpme out
Henry Wong

Joined: Sep 28, 2004
Posts: 20352


I would highly recommend that you pick up a book about regular expressions (or google for a tutorial). Regular expressions are incredibly powerful, and can't really be learned easily with examples.

But to answer your question... assuming that you have one line of the file in a string, here is how regex can be used to remove the first field...


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Wong

Joined: Sep 28, 2004
Posts: 20352

Okay, got a bit too fancy there. Here is a much simpler version...

I agree. Here's the link:
subject: using Regex
It's not a secret anymore!