Solved

Regular Expression (Find and Replace)

Posted on 2011-03-25
10
268 Views
Last Modified: 2012-05-11
Hi,

In one of my file I have the data as below

04001-AP107-6718,2005,"5,939",0,0,"5,939","6,117","2,630",10.52,

here I would like to replace "5,939" with "5939".

Please suggest a way out.
0
Comment
Question by:PraveenKumarGautam
  • 5
  • 4
10 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 35218582
You don't even need a regex for that:
line = line.replace("5,939", "5939");

Open in new window

0
 

Author Comment

by:PraveenKumarGautam
ID: 35218592
I need a regular expression that can work in Notepad++ for this data
0
 

Author Comment

by:PraveenKumarGautam
ID: 35218614
I just want to do the similar find and replace(as mentioned in the question) in the whole file
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 47

Expert Comment

by:for_yan
ID: 35218668
Notepad really works in this way withou problems - you put the Find box "5,939" in the replace box: "5939" and replace all will work
Do you mean you want to follow the general pattern als replacing "6,110" with "6110", etc - ?
0
 

Author Comment

by:PraveenKumarGautam
ID: 35218721
Yes I am looking for a general pattern
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35218791
Try
String PAT = "(\"\\d+),(\\d+\")";
line = line.replaceAll(PAT, "$1$2");

Open in new window

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 100 total points
ID: 35218809
In an editor that would (if it allows it) would be something like
Find: ("[0-9]+),([0-9]+")
Replace: \1\2

Open in new window

0
 

Author Comment

by:PraveenKumarGautam
ID: 35218872
I tried the same in Notepad++ but it is replacing the numbers with $1$2 rather then the desired results
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35218881
It would be more like what i posted here http:#35218809
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35219573
:)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question