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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:20:25+00:00 2026-06-05T09:20:25+00:00

String temp = 77; // It can be 0 or 100 or any value

  • 0
String temp = "77"; // It can be 0 or 100 or any value

// So the pattern will be like this only but number can be change anytime
String inclusion = "100;0;77;200;....;90";

I need to write a regular expression so that I can see whether temp exists in inclusion or not so for that I wrote a regexPattern like this.

// This is the regular Expression I wrote.
String regexPattern = "(^|.*;)" + temp + "(;.*|$)"; 

So do you think this regular expression will work everytime or there is some problem with that regexPattern?

if(inclusion.matches(regexPattern)) {

}
  • 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-05T09:20:27+00:00Added an answer on June 5, 2026 at 9:20 am

    You could run into issues if temp can contain special characters for regular expressions, but if it is always integers then your method should be fine.

    However, a more straightforward way to do this would be to split your string on semi-colons and then see if temp is in the resulting array.


    If you do stick with regex, you can simplify it a bit by dropping the .*, the following will work the same way as your current regex:

    "(^|;)" + temp + "(;|$)"
    

    edit: Oops, the above will actually not work, I am a bit unfamiliar with regex in Java and didn’t realize that the entire string needs to match, thanks Affe!

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

Sidebar

Related Questions

This fails string temp = () => {return test;}; with the error Cannot convert
string temp = Membership.GetUser(o.username).UserName; o.username is a string but the function expects a Guid,
I have the following String[] temp; which returns red blue green I would like
So, I have a vector std::vector<std::string> lines. I fill this vector up, and can
I have string like this /c SomeText\MoreText Some Text\More Text\Lol SomeText I want to
for example, can i do this: split = temp_string.Split(<beginning of record>) those of you
String[] temp = new String[adapter.getCount()]; for(int i = 0; i < adapter.getCount(); i++) temp[i]
string temp is equal to ZERO:\t.WORD\t1 from my debugger. (the first line of my
SOLUTION Thanks to 1111... vector<std::string> split_at_line(string str, int lines) { vector<std::string> nine_ln_strs; string temp;
i have this: Dim split As String() = temp_string.Split(,) ''#feed all info into global

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.