Hi,
I'm new at regular expressions and need a little help to get started. I have several plain text files that contain multiple lines. Some of those lines start and end with a specific character. This could be an asterisk or a letter.
Here's an example:
Polly wants a cracker
Oswald has a cookie but does not share with others
b Carmen goes to school with a lunchbox full of treats b
Michelle doesn't eat potato chips
I would like to find the sentences that have leading and ending characters and remove those. So in the example I'd like to find the sentence b Carmen goes to school with a lunchbox full of treats b and remove the b in the beginning and end of the line.
Can anyone help me with the regex for this?
Find and replace lines prefixed with a specific character
Re: Find and replace lines prefixed with a specific characte
Ok, I've found an expression that seems to find the correct line, but I still haven't figured out what to replace it with.
Find: \r\n(b\s)|(\sb)\r\n
Replace: ???
Any help would be greatly appreciated.
Find: \r\n(b\s)|(\sb)\r\n
Replace: ???
Any help would be greatly appreciated.
- DigitalVolcano
- Site Admin
- Posts: 1804
- Joined: Thu Jun 09, 2011 10:04 am
Re: Find and replace lines prefixed with a specific characte
Try this: (with multi-line anchors turned on)
Code: Select all
Regex:
\r\nb(.*)b\r\n
Replace:
\r\n$1\r\n
Re: Find and replace lines prefixed with a specific characte
Works like a charm, except for the longer sentences that have a line break in them. But I can catch those by splitting it into 2 separate commands.
Thanks for your help!
Thanks for your help!