0

I am exporting an LDAP database into an LDIF, and I need to clean it up a bit. There are some attributes that I no longer want. If it is a one-line attribute it is simple:

# Entry 23: cn=dwhite,ou=ORG1,o=Root
dn: cn=dwhite,ou=ORG1,o=Root
objectclass: person
objectclass: inetorgperson
objectclass: webadmaccount
sn: white
cn: dwhite
description: don.white@company.com
givenname: Don
mail: 5551234567@txt.att.net
o: ORG1
uid: dwhite
userpassword: {SSHA}YrGx7L7L8xxxiMzuUzL+f0j+i73uFTYEPnu
webadmdata: OpenOTP.RejectCount={wcrypt}eAw+r6VX6l8lioB+1KX/6A==,OpenOTP.Las
 tLogin={wcrypt}hQCwWl0KRdsiXyG7UPxPxo/WphEkyD6NPTKor8FCA5E=,OpenOTP.LoginCot
 0f5vQVl1ippSdKFiGeACiJbFWHsfs=,DataMode=A8tMd3g=

# Entry 24: ou=ORG2,o=Root
dn: ou=ORG2,o=Root
objectclass: organizationalunit
ou: ORG2

# Entry 25: cn=jlee,ou=ORG2,o=Root
dn: cn=jlee,ou=ORG2,o=Root
objectclass: person
objectclass: inetorgperson
objectclass: webadmaccount
sn: Lee
cn: jlee
userpassword: {SSHA}+CreNAoXMO3XMIWxxaWsA2r3ozyeCBEShn
description: jay.lee@company.com
givenname: Jay
mail: 5551234567@txt.att.net
o: ORG2
uid: jlee
webadmdata: OpenOTP.RejectCount={wcrypt}OrtNikuuHCyBruxUTOq6eg==,OpenOTP.Las
 tLogin={wcrypt}WUa965R8rFV9iHx7LrXrfzxEE3Gjd7TGiFz8AEJBmwU=,OpenOTP.LoginCo
 unt={wcrypt}Qbamc7jYTL+14K1yaZS9kA==,OpenOTP.LastOTP={wcrypt}t+fDlGfP6kGIse
 at8PHJdxJy15LSN4R+tJXr7B7L7+4=,DataMode=A8tMd3g=

In the sample above to remove the 'objectclass: webadmaccount' attribute, a Find and Replace with a regex like: ^objectclass.*webadmaccount$ will do the job. I know that seems a little overkill with the anchors, but elsewhere in the LDIF, you can find that sting embedded in a longer line, so the anchors.

Now, my problem comes when I want to get rid of the 'webadmdata:' attributes. You can see they are multiline, and not all the same length. This is where I am stuck, a regex like this: ^webadmdata:.*[\n\s]+.* will get the first two lines, but then it quits. If I make the .*[\n\s]+.* a capture group and repeat it with '+' at the end: (.*[\n\s]+.*)+ it will select the whole file (or crash vscode ). It seems like I should be able to write a regex that will select everything from ^webadmdata to A8tMd3g=\n\n but I cannot for the life of me get it to work. I hope there is a regex or VSCode guru out there that can help. Thanks in advance.

1 Answers1

0

OK, I don't know why I thought this didn't work before, but it does. The following regex will do what I want: ^webadmdata:.(.|\n)+?A8tMd3G=$\n

Apparently VSCode defaults to lazy qualifier. See below: screenshot