Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find and replace contents of a bracket inside notepad++

I have a large file with content inside every bracket. This is not at the beginning of the line.

1. Atmos-phere (7800)
2. Atmospheric composition (90100)
3.Air quality (10110)
4. Atmospheric chemistry and composition (889s120)
5.Atmospheric particulates (10678130)

I need to do the following

  1. Replace the entire content, get rid of line numbers
    1.Atmosphere (10000) to plain Atmosphere

  2. Delete the line numbers as well 1.Atmosphere (10000) to plain Atmosphere

  3. make it a hyperlink 1.Atmosphere (10000) to plain <a href="http://blahqd.com/Atmosphere.htm">linky study</a>

  4. [I added/Edit] Extract the words into a new file, where we get a simple list of key words. Can you also please explain the numbers in replace the \1\2, and escape on some characters

    1. Each set of key words is a new line
      Atmospheric
      Atmospheric composition
      Air quality

    2. Each set is a on one line separated by one space and commas
      Atmospheric, Atmospheric composition, Air quality

I tried find with regex like so, \(*\) it finds the brackets, but dont know how to replace this, and where to put the replace, and what variable holds the replacement value.

like image 866
aroos Avatar asked May 26 '13 16:05

aroos


People also ask

How do I find and replace a pattern in Notepad++?

Using Regex to find and replace text in Notepad++ In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the 'Regular expression' radio button is set.

How do I use the Find tool in notepad?

Find tab: Gives access to searching and counting. It can be invoked directly with Search > Find or the keyboard shortcut Ctrl+F . Replace tab: Similar to Find tab, but allows you to replace the matched text after it's found. It can be invoked directly with Search > Replace or the keyboard shortcut Ctrl+H .


1 Answers

Here is mine exression for notepad ([0-9(). ]*)(.*)(\s\()(.*)

  1. You need split your search in groups

    1. ([0-9. ]*) numbers, spaces and dots combination in 0 or more times

    2. (.*) everything till next expression

    3. (\s\() space and opening parenthesis

    4. (.*) everything else

  2. In replace box - for practicing if you place

    1. \1\2\3\4 this do nothing :) just print all groups from above from 1.1 to 1.4

    2. \2 this way you get only 1.2 group

    3. new_thing\2new_thing adds your text before and after group

    4. <a href=blah.com/\2.html>linky study</a> so now your text is added - spaces between words can be problematic when creating link - so another expression need to be made to replace all spaces in link to i.e. _

    5. If you need add backslash as text (or other special sign used by regex) it must be escaped so you put \\ for backslash or \$ for dolar sign

Want more tune - <a href=blah.com/\2.html>\2</a> add again 1.2 group - or use whichever you want

On the screenshot you can see how I use it (I had found and replaced one line) enter image description here

Ok and then we have case 4.2 with colon at the end so simply add colon after extracted section:

change replace from \2 to \2,

Now you need join it so simplest way is to Edit->Line Operations->Join Lines but if you want to be real pro switch to Extended mode (just above Regular expression mode in Replace window) and Find \r\n and replace with space.

Removing line endings can differ in some cases but this is another story - for now I assume that you using windows since Notepad++ is windows tool and line endings are in windows style :)

like image 117
pbaranski Avatar answered Nov 15 '22 07:11

pbaranski