Find and Replace pattern that includes a variable string of text

680 views
Skip to first unread message

Ralph Hawkins

unread,
Nov 7, 2021, 10:18:07 AM11/7/21
to BBEdit Talk
Greetings all.  First time post.  

I need to find and replace a consistent block of HTML that wraps around a variable string of text, like this:

XXXXXXXXXX
adiuhkjashfutrhat
XXXXXXXXXX

and

XXXXXXXXXX
hjsutqpds
XXXXXXXXXX

etc.

I need to replace XXXXXXXXXX with YYYYYYYYY

resulting in this 

YYYYYYYYYY
adiuhkjashfutrhat
YYYYYYYYYY

and

YYYYYYYYYY
hjsutqpds
YYYYYYYYYY


Is there a GREP term or switch that will grab a string of VARIABLE text and carry it over to a replace across dozens of instances?

Thanks all.  

Hawk in Macon

jj

unread,
Nov 7, 2021, 12:10:18 PM11/7/21
to BBEdit Talk
Hi Ralph,

Find:

(?s)XXXXXXXXXX(.+?)XXXXXXXXXX

Replace:

YYYYYYYYY\1YYYYYYYYY

Some explanation:

(?s) means allow the dot (which is the regular expression wildcard character) to match at new lines.
(.+?) means capture one or more characters non-greedily.
\1 is the result of that capture.

For anything touching regular expression patterns you should check the excellent BBEdit's menu Help >  BBEdit Help > Grep Reference.

HTH,

Jean Jourdain
Reply all
Reply to author
Forward
0 new messages