java - Check if String contains regex match -


I am working on a program that is an interpreter for a simple language that works with the group and sets Operates. It currently works with the holding numbers set.

When the user defines the set, then the input looks like this: set1 = {1, 25, 5, 6};

such as set1 = {1, 25, 5, 6} can also work, but

do something like this Set1 = {1 25, 5,6}; should not

so basically it does not matter to the empty space, if any "," between numbers it's OK.

What I need to check is what is there in string

between any "," , anywhere After the blank space and the second number, I am doing this:

  Pattern Pattern = Pattern.compile ("[0-9] [\" \ "] + [0- 9]" ); Matcher matcher = pattern.matcher (input); If (matcher.find ()) false return;   

And it works just fine. But this is a university assignment and I'm not sure that I have permission to use the pattern and Matcher .

So my question is, is there any other way that I can see that there is a regex in any string ? Or is there any other easy way to get it?

Since this is an assignment, I will not write code outside, but there is an alternative solution:

  • , Divide the string on the token (using String.split () )
  • Each of the resulting split array For the Member:
    • Trim the leading and the following empty space from the member
    • If the trimmed member is an integer (I will give you
    • otherwise:
        < Li> It is possible to determine For that:
        • The tokens can meet your criteria (which contain several integers and spaces, but no commas. You have several ways to determine it: "" while loop, or maybe something else. I'll tell you this.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -