Regular expressions - Replace one asterisk with two

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
User avatar
boldan
Posts: 31
Joined: Tue Jul 22, 2003 2:47 pm
Location: Toronto
Contact:

Regular expressions - Replace one asterisk with two

Post by boldan »

I need to change in many SAS programs one-asterisk comments with two-asterisk comments and insert a space after the second asterisk. The comments are following a semicolon.

Example, the following line:

data a; *create data a;

shuld change into:

data a; ** create data a;

I figured out:
Find What: "; \x2a\\[:a-z:]" (without the quotes)

but I can't do the:
Replace With:

Of course, I don't want to replace 2 asterisks with 3 asterisks.
User avatar
boldan
Posts: 31
Joined: Tue Jul 22, 2003 2:47 pm
Location: Toronto
Contact:

Post by boldan »

Oops, the Find What should be:
; \x2a[:a-z:]
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Hello boldan.....

You wrote:

I need to change in many SAS programs one-asterisk comments with two-asterisk comments and insert a space after the second asterisk. The comments are following a semicolon.

Example, the following line:

data a; *create data a;

shuld change into:

data a; ** create data a;
==========================
:idea: Try this:

Search: \(; \*\)\([^\*]\)

Replace: \1* \2

===============================
Explanation of Regex Search Example:
\( = start of first tagged expression)
; = semicolon
= space
\* = an asterisk
\) = end of first tagged expression
\( = start of second tagged expression
[^\*] = any character execept an asterisk
\) = end of second tagged expression

Explanation of Regex Replace Example:
\1 = first tagged expression
* = asterisk
= space
\2 = second tagged expression
=============================
Common English expression: Find a string of a semicolon followed by a space followed by a single asterisk and replace that string with itself, insert an asterisk and a space, and replace the second remaining string.

:!: I did this to look for only one * in case you already had code that had been replaced and was correct. I did not want to ruin that which was already OK.

Hope this helps..............good luck, :D
Bob
Post Reply