Solved

Regular Expression (Find and Replace)

Posted on 2011-03-25
10
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 44
ejb on wildfly 5 60
regex code: words must be 6 to 8 characters long ? 2 49
Java import explained 4 44
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

736 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