Solved

Regular Expression (Find and Replace)

Posted on 2011-03-25
10
269 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

830 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