Question

Create a regular expression to filter a specific data set. here is the example Write a...

  1. Create a regular expression to filter a specific data set.

  2. here is the example

  3. Write a regular expression that can represent any binary byte value, that is, that is, any eight-bit number with or without spaces in between each nibble. Valid input tests: 10100001 and 1010 0001 Invalid input tests: 10a0b0c0 and 00000000000000000000

  4. This is one possible regular expression for representing a binary byte value: [01]{4}[ ]?[01]{4}.

  5. In addition to the description, provide two test cases that will pass the input and one that will fail

  6. So pretty much creating the specific topic using the regular expression and to filter specific data set.

  7. The topic of the set can be about anything /Use JAVA for the code plz thank you.

Homework Answers

Answer #1

The regex can be defined as: \b[01]{8}\b

This code will determine if the string is accepted or not.

// Java regex program to check for valid string 

import java.util.regex.Matcher; 
import java.util.regex.Pattern; 

class GFG 
{ 
        // Method to check for valid string 
        static boolean checkString(String str) 
        { 
                // regular expression for invalid string 
                String regex = "[01]{8}"; 
                
                // compiling regex 
                Pattern p = Pattern.compile(regex); 
                
                // Matcher object 
                Matcher m = p.matcher(str); 
                
                // loop over matcher 
                while(m.find()) 
                { 
                        // if match found, 
                        // then string is invalid 
                        return false; 
                } 
                
                // if match doesn't found 
                // then string is valid 
                return true;     
        } 

        // Driver method 
        public static void main (String[] args) 
        { 
                String str = "00000000"; 
                
                System.out.println(checkString(str) ? "VALID" : "NOT VALID"); 
        } 
} 
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions