Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8759957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:55:58+00:00 2026-06-13T14:55:58+00:00

I am a newbie in using Regexp Can anyone please provide required regexp to

  • 0

I am a newbie in using Regexp

Can anyone please provide required regexp to find all C++ code lines inside a C++ source code file used to declare a variable?

Some of the methods variables can be declared could be as mentioned below:

int  x;
int  y=9;
int  x,y;
int  x,y=0;
int  x,y=0,c;
short const x=9;
int* x,y,c=null;
short const *x=NULL;
MyObj aobj();
MyObj aobj(x,y);
Myobj * a = dynamic_cast<A *>(b);
String x = "test";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T14:55:59+00:00Added an answer on June 13, 2026 at 2:55 pm

    The following regex will get you started:

    (int|short|MyObj|String).*(;)
    

    breakdown:

    1. (int|short|MyObj|String) = It will search for any of the listed items. A | can be added to the list along with more options.
    2. .*(;) = all characters up to the first ;, basically meaning to the end of the line.

    The problem is, there can be many ways to declare a variable. In your example alone there are 4 (5 if you count for case-sensitivity) ways to declare. Unless this is just a quick one time thing, I would look for what Richard mentioned about getting a complete parser. I’m not familiar with C++ enough to help you with that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie question since I'm not up to speed using maven at all. I'm trying
I'm a newbie to SCons and also using pydev. Can someone help me with
I am using a regex pattern to find instances of [code][/code] BB tags. (This
I'm newbie in Perl regexp programming (using it in .NET RegExp class), so for
I'm a newbie using Ninject and I can't figure out how to inject into
I am (newbie) using Kohana V 3.0.3 and my directory structure is: pojectsys (kohana's
I was newbie in using sqlite database android. and now I have a problem
I am newbie at using DataSet. I am writing a program with VB.NET, there
I am quite a newbie in OOP using java and I'm learning as I
I am a newbie java dev using netbeans IDE 7.1.1 and im watching this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.