Desktop productivity for business analysts and programmers

Regular expression search and replace in SAS EG is broken

Accepted Solution Solved
Reply
Super Contributor
Posts: 386
Accepted Solution

Regular expression search and replace in SAS EG is broken

EG 6.1 M1 (6.100.0.4025) (32-bit)

 

I pasted a bunch of text from Excel (list of variable names, one per line) into EG.

 

I now want to make them comment headers for each code block.

 

So, I tried:  Cntl-H, Find text = ^, Replace with = \* , tick Regular expression search, click Replace All (or Replace in Selection).  

Error message "Cannot find the string "^" ".

 

Tried the same using the "right arrow/play button" pulldown for ^ Start of line.  Same error.

 

Also tried:  Find text = $, Replace with = ; .  Same error.

 

Workaround:  paste into Textpad, search and replace (F8), do the same thing as above, it works fine.  Paste back into EG.

 

(In Textpad, Find text = ^(.*)$, Replace text = \* \1 ; does it all in one search and replace, which is kind of cool.)

 

Can anyone comment 1) if they also experience this issue in EG 6.x, and 2) is it fixed in later releases?

 


Accepted Solutions
Solution
‎05-10-2017 02:03 AM
SAS Super FREQ
Posts: 306

Re: Regular expression search and replace in SAS EG is broken

You are actually running into two limitations of the Find/Replace dialog in the EG editor...

 

1) It doesn't currently handle zero-width regular expression matches (such as lone ^ and $).  If you use those anchors in regular expressions that return greater-than-zero-width matches, it'll find the matches just fine.

 

2) It doesn't currently allow regular expression substitutions in the replacement text.  (ex. a capture)

 

We are aware of both of these limitations (which still exist in the latest version of EG) and hope to be able to address them in a future release.

 

Casey

View solution in original post


All Replies
Super User
Posts: 11,134

Re: Regular expression search and replace in SAS EG is broken

The regular expression parser in the editor seems to be only a subset of regular expressions.

Part of the issue with the search and replace in the editor is that it has to handle the non-regular expressions as well.

 

You might be able to use

Search for \n

Replace \n/*

for the start of a line

or search \n

replace */\n for end of line

 

but generally I would find the editor Ctrl-/ on a block or line of text easier.

Solution
‎05-10-2017 02:03 AM
SAS Super FREQ
Posts: 306

Re: Regular expression search and replace in SAS EG is broken

You are actually running into two limitations of the Find/Replace dialog in the EG editor...

 

1) It doesn't currently handle zero-width regular expression matches (such as lone ^ and $).  If you use those anchors in regular expressions that return greater-than-zero-width matches, it'll find the matches just fine.

 

2) It doesn't currently allow regular expression substitutions in the replacement text.  (ex. a capture)

 

We are aware of both of these limitations (which still exist in the latest version of EG) and hope to be able to address them in a future release.

 

Casey

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 216 views
  • 0 likes
  • 3 in conversation