Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with regex in VS2008

Help with regex in VS2008

Scheduled Pinned Locked Moved C / C++ / MFC
regexhelp
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    theCPkid
    wrote on last edited by
    #1

    I am trying to replace

    if(watever)
    somecode;

    with

    if(watever)
    {
    somecode;
    }

    (if\([^`]*\))([ \n])([^`]*[;]) This regex finds out all such if blocks but when I try to replace \3 with {\3}, I get nothing; meaning \1, \2, \3 are just empty. \0 has value and it is equal to the complete string found. I expect \1 = (if\([^`]*\)) \2 = ([ \n]) \3 = ([^`]*[;]) It may be obvious by now that this is the first time I am using regex. Please suggest.

    T 1 Reply Last reply
    0
    • T theCPkid

      I am trying to replace

      if(watever)
      somecode;

      with

      if(watever)
      {
      somecode;
      }

      (if\([^`]*\))([ \n])([^`]*[;]) This regex finds out all such if blocks but when I try to replace \3 with {\3}, I get nothing; meaning \1, \2, \3 are just empty. \0 has value and it is equal to the complete string found. I expect \1 = (if\([^`]*\)) \2 = ([ \n]) \3 = ([^`]*[;]) It may be obvious by now that this is the first time I am using regex. Please suggest.

      T Offline
      T Offline
      theCPkid
      wrote on last edited by
      #2

      Visual studio Tag expression is {} and not (). If I use {} instead of (), I get correct values in %1, %2. Any idea how can I properly indent the inserted brackets. THey are inserted at start of line whereas 'if' can be indented?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups