Question

In: Computer Science

Java:    Find a pattern that will match any string that is --  at least 6 characters...

Java:

   Find a pattern that will match any string that is

--  at least 6 characters long,

-- and begins with a letter or number (\w)

-- and contains at least one non-letter and non-number (\W).

Solutions

Expert Solution

Question

Java:

   Find a pattern that will match any string that is

--  at least 6 characters long,

-- and begins with a letter or number (w)

-- and contains at least one non-letter and non-number (W).

Program :

import java.util.regex.*;
import java.util.Scanner;
class RegexExample1{
   public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter a string : ");
      String content = sc.next();

      String pattern = "(^w(?=.*W).{6,})";

      boolean isMatch = Pattern.matches(pattern, content);
      System.out.println("Given string matched to the regular expression" + isMatch);
   }
}

OUTPUT :


Related Solutions

Given a string of at least 3 characters as input, if the length of the string...
Given a string of at least 3 characters as input, if the length of the string is odd return the character in the middle as a string. If the string is even return the two characters at the midpoint. -------------------------------------------------------------- public class Class1 { public static String midString(String str) {     //Enter code here } }
1. Given a string of at least 3 characters as input, if the length of the...
1. Given a string of at least 3 characters as input, if the length of the string is odd return the character in the middle as a string. If the string is even return the two characters at the midpoint. public class Class1 {    public static String midString(String str) { //Enter code here } } ----------- 2. Given an array of integers return the sum of the values stored in the first and last index of the array. The...
Write Java code that prompts the user for a string and tells them if the grouping characters in that string are balanced.
Write Java code that prompts the user for a string and tells them if the grouping characters in that string are balanced. Grouping characters are ( and ), [ and ], and { and }. I got the basic idea for this problem from HackerRank. It’s also a very common interview question.*******************8Example output**************Enter the expression:{[()]} {[()]}is balancedEnter the expression: {()()} {()()}is balancedEnter the expression: {([[])} {([[])}is not balancedEnter the expression: {([)]} {([)]}is not balanced
For each of the strings below, does the pattern [^O]*o+ match the string? If so, list...
For each of the strings below, does the pattern [^O]*o+ match the string? If so, list which part of the string will be matched. If not, then state "no match". (a) balloons (b) FOODY (c) bookstore (d) "Look" (e) PoolRoOM
Java- creat a method that takes two char parameters. Return a String containing all characters, in...
Java- creat a method that takes two char parameters. Return a String containing all characters, in order, from the first char parameter (inclusive) to the last (inclusive). For instance, input('a', 'e'), and return "abcde".
JAVA: (Find yourself in PI) In this assignment you will find a numeric string (if it...
JAVA: (Find yourself in PI) In this assignment you will find a numeric string (if it exists) within a file containing the first 1 million characters of the decimal expansion of PI. The numeric string in question is a 6 character string representing your birth date. E.g., if your birth date is January 1, 1984, then the string is 010184. The file containing the first 1 million characters of the decimal expansion of PI is named pidigits.txt and is available...
Find a valid tax court case to match the fact pattern evident in the case presented...
Find a valid tax court case to match the fact pattern evident in the case presented below: CPA Joe reimburses a client for a $75,000 tax liability that is traceable to Joe’s ineffective tax advice. For fear of increasing his already steep malpractice-insurance premiums, Joe does not file a claim with the insurer. Can Joe deduct the $75,000 loss? Facts in this case: Joe reimburses a client $75,000 due to his ineffective tax advice and he does not file a...
Write a JAVA code using regex methods and concepts The test string S should match the...
Write a JAVA code using regex methods and concepts The test string S should match the following requirements: S must be of length 6 First character should not be a digit (1, 2, 3, 4, 5, 6, 7, 8, 9 or 0). Second character should not be a lowercase vowel (a, e, i, o or u). Third character should not be b, c, D or E. Fourth character should not be a whitespace character (\r, \n, \t, \f or the...
use java recursion find # of times a substring is in a string but it has...
use java recursion find # of times a substring is in a string but it has to be the exact same, no extra letters attached to it and capitalization matters. input is 2 strings, output is an int input: ("Hello it is hello it's me hellos" + "hi hellllloooo hi hello" + "hello", "hello") should output: 3 input: (" Hello it is hello it's me hellos" + "hi hellllloooo hi hello" + "hello", "Hello") should output: 1 input: (" Hello...
use java recursion find # of times a substring is in a string but it has...
use java recursion find # of times a substring is in a string but it has to be the exact same, no extra letters attached to it and capitalization matters. input: school is boring with schooling and School substring: school output: 1
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT