Notepad++/Regular Expression to find line with same beginning, different ending

6,472

Solution 1

Another option would be

^Entry: NAME .*

Which will look for lines beginning with Entry: NAME and anything after that.

Solution 2

Using

^Entry: NAME ~\d+$

as the search pattern seems to work as requested.

I would personally recommend matching using the \d placeholder (which matches any single digit in the range from 0 to 9) instead of a more general . placeholder. In fact, you should even make it:

^Entry: NAME ~\d{12}$

to specify that you expect exactly 12 digits in a row. This way, if an entry might contain something you didn't expect, you don't replace it by accident.

If the string turns out to be in hexadecimal notation, you might use:

^Entry: NAME ~[0-9a-fA-F]{12}$

Please note that I didn't check if the last 2 examples work properly in Notepad++, but to my knowledge, that's all pretty basic syntax.

Share:
6,472

Related videos on Youtube

Ravindra Bawane
Author by

Ravindra Bawane

Updated on September 18, 2022

Comments

  • Ravindra Bawane
    Ravindra Bawane over 1 year

    So, I've read a bit and found NotePad++ doesn't use "normal" regex (starting to think I'll just go back to SciTE), but here's my question:

    I've got an exported list of data with some redundant data that I'm trying to clean up and convert into a good CSV for import into address books (migrating a Fax server solution, the old one is OOOOLD and so this is the best I can got for export).

    The line I'm trying to remove from each entry group always starts

    Entry: NAME ~

    And then there is a 12 digit alphanumeric (is appears to be Hexadecimal) code that follows that is unique for each entry group. For a few entry groups there is a human-readable entry following "NAME", but these are few enough I can remove them manually, so matching them isn't a big chore.

    So what I want to do is to find every line that begins with Entry: and select it all the way to the end of the line. Each entry in each group is on a separate line. Then I'll use Find & Replace to remove these lines from the list.

    UPDATE: Input & Outpu

    Entry: NAME ~00003193820
    ShortName: ~00003193820
    Owner: USRENAME
    Name: John
    FamilyName: John
    DearName: John
    Organisation: Acme 1 Corp
    Via: FAX-ANY 1(555) 123-4567
    
    Entry: NAME ~00003193820
    ShortName: ~00003193820
    Owner: USRENAME
    Name: Sam
    FamilyName: Sam
    DearName: Sam
    Organisation: Acme 2 LLC
    Via: FAX-ANY 1(555) 890-1234
    

    Here's two entry groups. I want to remove the lines beginning with "Entry:" from each and every group.

    • Raystafarian
      Raystafarian over 12 years
      Why not import into excel, do a text filter, and delete them that way. You can resave as csv
    • Ravindra Bawane
      Ravindra Bawane over 12 years
      That would work in this case. I'm also trying to learn how to do it in RegEx for future ability.
    • Siva Charan
      Siva Charan over 12 years
      please provide with input and expected output with examples
    • Raystafarian
      Raystafarian over 12 years
      @music2myear Roger that :)
  • Ravindra Bawane
    Ravindra Bawane over 12 years
    Ok. It was the "." that I was missing. What does the "." signify in RegEx?
  • Oliver Salzburg
    Oliver Salzburg over 12 years
    @music2myear The dot (.) is a placeholder meaning "(almost) any single character".
  • Ravindra Bawane
    Ravindra Bawane over 12 years
    I was going to say, matching only numeric characters wasn't going to do me much good...