Formating the text file

I am having a text file having some text to be remove enclosed within a defined tag and send an email with the modified text.
Example -
aaaaaaaaaaa–text–aaaaa
–text–
blank line
bbbbbb–text–bbbbbb

To accomplish this, I am using a regex and replacing the text enclosed within the tags (–) with “”. But, this approach removes the empty lines (paragraph change) as well.
Output-
aaaaaaaaaaaaaaaabbbbbbbbbbbb

To prevent this, I am using pre html tag before sending the email. it preserves the empty lines (paragraph change) but, it also preserve the empty line created as part of text replacement with “”
aaaaaaaaaaaaaaaa
blank line
blank line
bbbbbbbbbbbb

The expected output here is-
aaaaaaaaaaaaaaaa
blank line
bbbbbbbbbbbb

Please suggest.

You don’t need regex. Just use Replace. Replace -text- with the value you want there.

Thanks postwick for the quick response but the value between the tags (–) is not fixed and so i can not simply replace it.

This regex expression finds anything with the - around it. Make note that the dashes in your string are NOT the standard ASCII dash. They’re the extended ASCII dashes. Copy them from your file and paste them into your regex to make sure you’re using the correct dash.

(–.*–)

Thanks again postwick but that is well understood but just to avoid any confusion, lets consider a different tag like ‘234’. So the text to be removed will look like-

234 text to be removed 234

But, the main issue here remains same that how to get rid off the extra blank line that is formed as part the removal of the text enclosed within this tag.

Use .trim to get rid of leading and trailing spaces. If you’re trying to get rid of carriage returns then replace VbCrLf with “”

I had tried trim postwick but its not working. and no luck with VbCrLf either.

You need to show code. We can’t help if we don’t know exactly what code you’re trying.

Since I am a new user, I am unable to upload any attachment and so sharing the code, input and output file as below-

code-
1-read the input file
2- using string replace operation, replacing the output of step 1 using regex “(\d)([\s\S]*?)(\d)” with “”
3- writing the output of step 2 to another text file.

Input Text-

I am having a text file having some text to be remove enclosed within a defined tag and send an email with the modified text.
Example -
aaaaaaaaaaa234text234aaaaa
234textA234
blank line
bbbbbb234textB234bbbbbb

To accomplish this, I am using a regex and replacing the text enclosed within the tags 234 with “”. But, this 234 approach removes the empty lines (paragraph change) as well.
Output-
aaaaaaaaaaaaaaaabbbbbbbbbbbb

234To prevent this, I am using pre html tag before sending the email. it preserves the empty lines (paragraph change) but, it also preserve the empty line created as part of text replacement with “”
aaaaaaaaaaaaaaaa234
blank line
blank line
bbbbbbbbbbbb

Output text-

I am having a text file having some text to be remove enclosed within a defined tag and send an email with the modified text.
Example -
aaaaaaaaaaaaaaaa

blank line
bbbbbbbbbbbb

To accomplish this, I am using a regex and replacing the text enclosed within the tags  approach removes the empty lines (paragraph change) as well.
Output-
aaaaaaaaaaaaaaaabbbbbbbbbbbb


blank line
blank line
bbbbbbbbbbbb

Issue-
In output file, row 4 and 12 should not be there

This is what your RegEx expression is matching:

Yes… Thats correct… No complaint with that as it was just an example… But if you also have noticed the lines that are to be removed entirely, are leaving the blank line behind… I needed to get rid of that…
I am not sure if I can simplify my query any further.
Thanks