IDE Find and Replace using RegEx

I have some old code that has c. 27,000 deprecations. One of these is replacing array Ubound with LastIndex. I have a lot of instances of Ubound(arrayname) that I need to change to arrayname.LastIndex. The IDE’s Find/Replace function has a Regex feature, but I’m not familiar with such arcane arts. Can someone who is tell me the Regex code needed in the search and replace fields to do this?

Saves me spending hours buried in books and websites…

Search:

\bUbound *\( *(\w+) *\)

Replace:

\1.LastIndex
2 Likes

Let me break that down.

\b = word boundary
Ubound = match these characters (case doesn't matter)
<space>* = zero or more spaces
\( = literal open paren
<space>* zero or more spaces
(\w+) = match one or more word characters (letters, numbers, underscore) in a group
<space>* = you know
\) = literal close parentheses 

This should match no matter your coding style.

1 Like

Brilliant. Thanks. That dealt with 90%+ of the situations. However, I have a lot of situations such as:

ubound(gprefs.PCW.Telescopes)

You want to suggest a solution? I can probably figure it out myself (with the help of your excellent RegexRx application).

Replace \w+ with [\w.]+

2 Likes

Perfect. Thanks again.

1 Like