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

  • Home
  • SEARCH
  • 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 6998515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:25:16+00:00 2026-05-27T20:25:16+00:00

String input = scanner.nextLine(); Pattern pattern = Pattern.compile(the [a-z]+ jumped over the [a-z]+ )

  • 0
String input = scanner.nextLine();
Pattern pattern = Pattern.compile("the [a-z]+ jumped over the [a-z]+ ")
Matcher matcher = pattern.matcher(input);
if (matcher.matches()) {
    // how do I print out what jumped over what???
}

In this example, someone will type something like “the cow jumped over the moon” or
“the fox jumped over the dog” or “the cat jumped over the mouse” …
I will need to be able to figure out what values they put into the two placeholders.
So my question is how do I get the values of the two [a-z]+ spots in the regex.

  • 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-05-27T20:25:17+00:00Added an answer on May 27, 2026 at 8:25 pm

    You use capturing groups which are marked by parantheses: "the ([a-z]+) jumped over the ([a-z]+)".

    Then use matcher.group(1) and matcher.group(2) to retrieve them (group 0 is always the entire match).

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

Sidebar

Related Questions

I have this code: import java.util.Scanner; public class Example { public static void main(String[]
I have a string input = "maybe (this is | that was) some ((nice
So given this input string: =?ISO-8859-1?Q?TEST=2C_This_Is_A_Test_of_Some_Encoding=AE?= And this function: private string DecodeSubject(string input) {
The input string is something like this: LineA: 50 LineB: 120 LineA: 12 LineB:
I'm trying to take string in input using Scanner. But it asks me more
This example demonstrates using Scanner to read a file line by line (it does
System.out.println(Please enter the required word :); Scanner scan2 = new Scanner(System.in); String word2 =
I'm doing simple string input parsing and I am in need of a string
public static boolean palindrome(String input, int i, int j) { if (i >= j)
I have a string input that i do not know whether or not is

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.