Author Topic: Need a regex replace string  (Read 1953 times)

0 Members and 1 Guest are viewing this topic.

pkohut

  • Bull Frog
  • Posts: 483
Need a regex replace string
« on: June 06, 2011, 05:52:27 PM »
With this group having the most traffic...
I need a regex replace string for the following pattern

Original string:
m_somevariablename

Replace string:
somevariablename()

Basically, match "m_*" and replace with "*()". There's close to 500 of these in one particular file.

If it matters, this will be used in VS's find and place dialog.
TIA

edit:
Sample text:
Code: [Select]
   // common
    BS_ARCHIVE(bitcode::BS, in, m_useri1,       "useri1");
    BS_ARCHIVE(bitcode::BS, in, m_useri2,       "useri2");
    BS_ARCHIVE(bitcode::BS, in, m_useri3,       "useri3");
    BS_ARCHIVE(bitcode::BS, in, m_useri4,       "useri4");
    BS_ARCHIVE(bitcode::BS, in, m_useri5,       "useri5");
    BS_ARCHIVE(bitcode::BS, in, m_splinesegs,   "splinesegs");
    BS_ARCHIVE(bitcode::BS, in, m_surfu,        "surfu");
    BS_ARCHIVE(bitcode::BS, in, m_surfv,        "surfv");
    BS_ARCHIVE(bitcode::BS, in, m_surftype,     "surftype");
    BS_ARCHIVE(bitcode::BS, in, m_surftab1,     "surftab1");
« Last Edit: June 06, 2011, 06:01:34 PM by pkohut »
New tread (not retired) - public repo at https://github.com/pkohut

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Need a regex replace string
« Reply #1 on: June 06, 2011, 06:17:58 PM »
Perhaps:

Code: [Select]
Pattern: "m_([^, ]*)"
Replace: "$1()"
« Last Edit: June 06, 2011, 06:23:50 PM by Lee Mac »

pkohut

  • Bull Frog
  • Posts: 483
Re: Need a regex replace string
« Reply #2 on: June 06, 2011, 06:29:40 PM »
Perhaps:

Code: [Select]
Pattern: "m_([^, ]*)"
Replace: "$1()"

Thanks Lee. Your solution works correctly on an online regex tester so I'll run it through grep in a few minutes. VS and Notepad++ refuse to do the replace, they just paste the "$1()" string.
New tread (not retired) - public repo at https://github.com/pkohut

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Need a regex replace string
« Reply #3 on: June 06, 2011, 06:36:57 PM »
You're welcome Paul.  :-)

pkohut

  • Bull Frog
  • Posts: 483
Re: Need a regex replace string
« Reply #4 on: June 06, 2011, 06:48:02 PM »
Got it for VS. Have to create a tagged expression-
Find:
m_{([^, ]*)}
Replace:
\1()

New tread (not retired) - public repo at https://github.com/pkohut

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Need a regex replace string
« Reply #5 on: June 06, 2011, 06:56:27 PM »
Cool stuff.

pkohut

  • Bull Frog
  • Posts: 483
Re: Need a regex replace string
« Reply #6 on: June 06, 2011, 06:56:43 PM »
Sweet!!! Finished the search and replace, everything still compiles and passes the checks that are in place.
New tread (not retired) - public repo at https://github.com/pkohut