Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So I never actually used Regular Expressions in depth.

I've got a config file consisting of thousands of lines looking like this:

"Line 1"=18341235645

"Line 2"=123784571

"Line 3"=86273485

"Line 4"=362234

...

"Line 400"=491237850

"Line 401"=491237850

What I want is to replace these line into for example this:

"Line 1"= 123

"Line 2"= 124

"Line 3"= 125

"Line 4"= 126

...

"Line 400"= 300

"Line 401"= 301

etc.

The numbers after the = are what I want to replace, they are unimportant in it's current form.

For example I want 400 likes replaced with 400-800, then another 400 lines replaced with 1200-1600, then yet another 400 lines replaced with 33000-33400, and so on and so forth.

How do I use the Regular Expressions in Notepad++ for this task?

share|improve this question
1  
I guess you are better off writing a batch script –  pratnala Mar 19 '13 at 10:42
1  
Where are the ranges (400-800, 1200-1600) coming from? Is it something you want to do programatically or manually? –  m4573r Mar 19 '13 at 10:45
    
Those ranges are what I want to be after the = . –  Don Salva Mar 19 '13 at 11:20

2 Answers 2

up vote 1 down vote accepted

Regex would work well for finding the information you want to remove, but won't help you with the replacement part, as it appears you want to have some logic around what the replacement is.

A simple scripting language would handle this handily.

Alternatively, you could try something like this in Excel:

  1. Open the file in Excel
  2. Highlight all the data and select Data > Text To Columns, and entering = as the delimiter and selecting {none} as the text qualifier
  3. After you do that, you should have all your keys in column A, and all the data you want to get rid of in column B
  4. Delete column B, and manually enter the values you want. Note you can put the first few rows in, the highlight, and just fill down by selecting the lower right hand corner of the cell (when the cursor turns to crosshairs) and click and drag. Formulas might also be useful.
  5. Put a formula in Column C of the form =A1&"="&B1 and fill that down the whole column
  6. Copy and paste all of column C into a new text file
share|improve this answer
    
This helped! Thanks! Can I do that in google docs too? If so, how? –  Don Salva Mar 21 '13 at 17:16
    
If you add the "Text to Columns" script from the Script Gallery; select Insert -> Script when in Docs, search for Text to Columns, and then the rest is basically the same. –  ernie Mar 21 '13 at 17:31
    
Yay! Thank you! Sorry to bug you again. Any way to automatically run the script each time I paste something there? –  Don Salva Mar 21 '13 at 17:48

That's not really a regex type problem. You can easily remove the =1234 using regex (replace =\d+$ with just blank) but you'd be better off loading the text into a single column in a spreadsheet (Excel or OpenOffice) to create the new numbering scheme.

In Excel just use the row number to create your number using a formula like:

=A1 & "=" & TEXT(ROW(A1),"0").

(Assumes that you have pasted your text into column A and set this formula for column B.)

share|improve this answer
    
Numbering scheme...how? I'm not very often working with excel. –  Don Salva Mar 19 '13 at 11:23
    
I've updated the answer with an Excel formula. If that's not what you want you might want to modify your question to show exactly what output you want to see. –  snowdude Mar 19 '13 at 12:43
    
Not what I meant. I edited my question. –  Don Salva Mar 20 '13 at 0:29
    
Ah yes, that works too. However I'm trying to do it in google docs, it would be great if I somehow could implement ernie's method. Because that would save me the step of removing the numbers after the = . With ernie's method, they'll be seperated in 2 columns. 1 purely text, 1 just numbers after the =. Then I can take the text column and use your method. –  Don Salva Mar 21 '13 at 17:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.