3

I have several many lines like this:

af - miracle asfsa
am - facut asfa
az - ali baba asfa
be - strong asas
ty - asfa asfsa
...

I want to select/delete all from lines after the first 2 letters. I made a regex, but it keep the space before the first 2 letters. I need to exclude also that space.

SEARCH: ^.?\w\W{1}.*?

The expected result should be:

af
am
az
be
ty
...
2
  • 1
    What is the expected result?
    – Toto
    Commented Oct 7, 2021 at 16:14
  • hi, Toto. I edit the topic with the expected result
    – Just Me
    Commented Oct 7, 2021 at 16:15

3 Answers 3

4
  • Ctrl+H
  • Find what: ^\w\w\K.+$
  • Replace with: LEAVE EMPTY
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Replace all

Explanation:

^           # beginning of line
    \w\w        # 2 word character
    \K          # forget all we have seen until this position
    .+          # 1 or more any character but newline
$           # end of line

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

1
1

an alternative:

  • Ctrl+F
  • Find what: ^[a-z]{2}\K.*$
  • CHECK Wrap around
  • CHECK Regular expression
  • Find All in Current Document

OR

  • Ctrl+F
  • Find what: (?<=^.{2}).*$
  • CHECK Wrap around
  • CHECK Regular expression
  • Find All in Current Document
0

The following sed script uses a regex to isolate the first 2 characters :

sed 's/\(..\).*/\1/'

It works as intended with your example.

1
  • 2
    not working on notepad++
    – Just Me
    Commented Oct 7, 2021 at 16:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .