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 6560497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:28:04+00:00 2026-05-25T13:28:04+00:00

Hi I am very new to regex but would like to construct something that

  • 0

Hi I am very new to regex but would like to construct something that will match on the word “Public” | “Private” | “Protected” and the following word (to grab the following word), unless the following word is not: void, string, int, bool. The bolded word matches can be any word except for the ones listed above.

Sample Matches:

  • Public xyz Functionname (match)
  • Public abc Functionname (match)
  • Private rbc Functionname (match)
  • Protected klm Functionname (match)

Sample Non-matches:

  • Public void Functionname (non-match)
  • Public string Functionname (non-match)
  • Public int Functionname (non-match)

I got as far as this but it’s not really working properly:

^((Public)|(Private)|(Protected)).*$(?<!Void|string|int)
  • 1 1 Answer
  • 1 View
  • 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-05-25T13:28:05+00:00Added an answer on May 25, 2026 at 1:28 pm

    Try this:

    \b(?:public|private|protected)\s+(?!void|string|int|bool)(\w+)\s+
    

    After a word break, match (but don’t capture) public or private or protected, then one or more whitespace characters, then one or more “word” characters as long as the word is not void or string or int or bool.

    Seems to work in my tests.

    Edit
    To exclude matches that end with get; or set;, it’s a bit more complicated but this appears to work:

    \b(?:public|private|protected)\s+(?!void|string|int|bool)(\w+)\s+((?!(get;|set;)$).)*$
    

    which I just like the first one with the addition of followed by any number of any character that is not followed by a get; or a set; which ends the line

    That will match Public xyz Functionname get; with other stuff but not Public xyz Functionname get;. If the former should be excluded as well, just drop the second to last $, and then a match will be discarded if there’s a get; or set; anywhere after the first section.

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

Sidebar

Related Questions

Very new to XSL (and XML for that matter), but I need to step
I'm trying to make a regex that would match this string: asf, Algeria, Wilaya
i'm pretty new on regex, i have learned something by the way, but is
I am very new to regex, but so far liking it's power. Incredible, although
I very new to Python, and fairly new to regex. (I have no Perl
Very new to C++ and Cocos2d-x but I was just toying around with CCArray
Very new to FluentNHibernate, but I'm also excited about the area. I've recently started
I'm VERY new to regex and can't get my head wrapped around it completely
My regex skills are not very good and recently a new data element has
I am very new to regex. I wanted to search for names and create

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.