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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:31:09+00:00 2026-06-13T10:31:09+00:00

I want to perform the following functionality : From a given paragraph extract the

  • 0

I want to perform the following functionality :

From a given paragraph extract the given String, like

String str= "Hello this is paragraph , Ali@yahoo.com . i am entering  random  email here as this one  AHmar@gmail.com " ; 

What I have to do is to parse the whole paragraph, read the Email address, and print their server names , i have tried it using for loop with substring method , did use indexOf , but might be my logic is not that good to get it , can someone help me with it please?

  • 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-13T10:31:11+00:00Added an answer on June 13, 2026 at 10:31 am

    You need to use Regular Expression for this case.

    Try the below Regex: –

    String str= "Hello this is paragraph , Ali@yahoo.com . i am " +
                "entering  random  email here as this one  AHmar@gmail.com " ;
    
    Pattern pattern = Pattern.compile("@(\\S+)\\.\\w+");
    Matcher matcher = pattern.matcher(str);
    while (matcher.find()) {
         System.out.println(matcher.group(1));
    }
    

    OUTPUT: –

    yahoo
    gmail
    

    UPDATE: –

    Here’s the code with substring and indexOf: –

       String str= "Hello this is paragraph , Ali@yahoo.com . i am " +
            "entering  random  email here as this one  AHmar@gmail.com " ;
    
       while (str.contains("@") && str.contains(".")) {
    
            int index1 = str.lastIndexOf("@");  // Get last index of `@`
            int index2 = str.indexOf(".", index1); // Get index of first `.` after @
    
            // Substring from index of @ to index of .      
            String serverName = str.substring(index1 + 1, index2);
            System.out.println(serverName);
    
            // Replace string by removing till the last @, 
            // so as not to consider it next time
            str = str.substring(0, index1);
    
        } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to perform the following actions from inside .NET code: Create a self-signed
Given the following text in Vim: [2] [3] [4] I want to perform a
I want to perform the following operations. Read 1 word at a time from
I want to write a procedure to perform a delete for the following i
I want to perform an SQL query that is logically equivalent to the following:
Following on from this earlier question , I've had a look at the Heroku
I want to perform the following operation: decimal = decimal? * float / 100
I have a set of line segments. I want to perform the following operations
I want to perform the following task using JSF / Richfaces On click of
I want to perform the following queries, to add a relation skos:related between node

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.