DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > Find/Replace in Visual Studio using Regular Expressions

Find/Replace in Visual Studio using Regular Expressions

David Amador user avatar by
David Amador
·
Feb. 09, 12 · Web Dev Zone · Interview
Like (0)
Save
Tweet
6.92K Views

Join the DZone community and get the full member experience.

Join For Free

usually find/replace gets the job done for what i need, although sometimes using “replace all” can break more stuff than it fixes.

but today i had this function i wanted to get rid of and simply change it with a public variable.

so i had something like this.

object->setlayer(/*blabal bla code, */);


i want to replace it with something more simple

object->z = /*blabal bla code, */;


so using visual studio find/replace in regular expressions mode i used this as a search string

setlayer\({.+}\);


and this as a replace with string

z=\1;


now, notice the first one, it’s actually simple, you have “setlayer”, followed by “\(” to tell the expression we really need to be that character, after that we have “.+”, which means match any single character except a line break and at least one occurrence. followed by “\);”

now if you notice we have curly brackets around the inside of what the function receives as parameter, that’s because we are tagging that string to use it later.

this way on the replace we simply need “z=” followed by the first tagged string we have “\1″. if we have more curly brackets it would be “\2″, “\3″ etc.

check the full list for more options: http://msdn.microsoft.com/en-us/library/2k3te2cs%28v=vs.80%29.aspx



source: http://www.david-amador.com/2012/01/findreplace-in-visual-studio-using-regular-expressions/

Strings Data Types Bracket (tournament) career IT

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Correlation Between Fast TTM and Containers
  • Getting Started With RSocket Kotlin
  • Regression Testing: Significance, Challenges, Best Practices and Tools
  • Learn the Weekly Rituals You Should Master as a Software Project Manager

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo