Notepad++ is a text and source code editor which supports several programming languages running under the MS Windows.

If you need to remove some texts before a character,

Cmd2.Parameters.AddWithValue(“@PosRefs”, textBox19.Text);
Cmd2.Parameters.AddWithValue(“@NSmoking”, textBox20.Text);
Cmd2.Parameters.AddWithValue(“@LongStay”, textBox21.Text);

For instance, I want to remove all texts before the punctuation mark  comma (,) in the above example.

[lists]

[/lists]

here X = the character (,)

I would like to replace it with empty string. By clicking “Replace All”, I got the following text:

textBox19.Text);
textBox20.Text);
textBox21.Text);

If you want to add some text before the above texts,

Find What: ^

Replace with: iam-

Result:

iam- textBox19.Text);
iam- textBox20.Text);
iam- textBox21.Text);

If you want to add some text after the above texts,

Find What: $

Replace with: last

Result:

iam- textBox19.Text);last
iam- textBox20.Text);last
iam- textBox21.Text);last

Remove text before Colons or vertical bar using Regex

Thanks for the questions by Yuri and Nicola.

vary:tetx:6yui8
ertyh:78umy:etrt
hbngt:ytrt:car

Yuri wanted to remove the text before the first colon character.

using

^.+(\:)(?=[^:]+:[^:]+$)

and replace with empty, the result will be

tetx:6yui8
78umy:etrt
ytrt:car

the same method applied for vertical bar(|). Nicola wanted

james|473702001|11|17|290
nox|473702001|41|89|431

to

473702001|11|17|290
473702001|41|89|431

This could be achieved by

Find this:
^.+(\|)(?=[^|]+\|[^|]+\|[^|]+\|[^|]+$)
Replace with:
Empty

Remove the second underscore using Regex

Lavanya’s question is to remove the last underscore.

10.0.0.0_19 ip-mask 10.0.0.0_19
10.0.0.0_19 ip-mask 10.0.0.0_19
10.0.0.0_19 ip-mask 10.0.0.0_19
10.0.0.0_19 ip-mask 10.0.0.0_19
10.0.0.0_19 ip-mask 10.0.0.0_19

  1. Find What: _(?=[^_]*$)
  2. Replace with: /
  3. Replace All

 

 

11 Responses

  1. I am trying to separate in a text of 200000 lines like this:

    vary:tetx:6yui8
    ertyh:78umy:etrt
    hbngt:ytrt:car

    to
    tetx:6yui8
    78umy:etrt
    ytrt:car

  2. how can i get output like this:

    james|473702001|11|17|290
    nox|473702001|41|89|431

    to

    473702001|11|17|290
    473702001|41|89|431

  3. I want to replace _char at the end and replace it with /
    10.0.0.0_19 ip-mask 10.0.0.0_19

    to
    10.0.0.0_19 ip-mask 10.0.0.0/19

  4. Hello, please can anyone help? 🙂

    90 L X+169,345 F1800
    905 L X+169,345 F1800
    90255 L X+169,345 F1800

    I want to replace every character before the “L”.
    Expected result:
    L X+169,345 F1800
    L X+169,345 F1800
    L X+169,345 F1800

    1. This is the same way as I wrote above
      Ctrl + F
      Click Replace
      Find what: .+(\X)
      Replace with your text

      Instead of just “L”, use ” L” (Space before L).
      .+(\ L)

Leave a Reply

Your email address will not be published. Required fields are marked *