Solved

Regular Expression (Find and Replace)

Posted on 2011-03-25
10
265 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now