post-title Regular Expressions – Remove texts before a character in notepad++ https://www.trilliardbytes.com/wp-content/uploads/Remove-texts-before-a-character.jpg 2018-02-28 05:46:30 yes no Posted by

Regular Expressions – Remove texts before a character in notepad++

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. here X = the […]

Posted by

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.

  • Ctrl + F
  • Click Replace
  • Find what: .+(\X) 
  • Replace with your text

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

 

 

Comments (6)

  1. yuri

    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

Leave a Reply

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

Latest News on our Blog

Loading…