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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:02:32+00:00 2026-06-09T08:02:32+00:00

I have a file that I’m parsing that ALWAYS includes an email address. The

  • 0

I have a file that I’m parsing that ALWAYS includes an email address. The file is currently laid out with a leading space before the @ and we want to capture the domain.

foo @bar.com more data here
foo @foo.com more data here

We want to pull out @bar.com and @foo.com and I’m just starting to work with regex. I’m trying to pull the pattern “@ at the start of a word boundary inclusive of all following characters up until the next word boundary“.

I’ve tried various iterations of the following, grouping things, square backets for the @ literal…but nothing seems to work.

EDIT – actual code :

import java.util.regex.*;
import java.io.*;
import java.nio.file.*;
import java.lang.*;
//
public class eadd
{
    public static void main(String args[])
    {
        String inputLine = "foo foofoo foo foo @bar.com foofoofoo foo foo foo";
        String eDomain = "";
       // parse eadd
        Pattern p2 = Pattern.compile("(\\b@.*\\b)");
        Matcher m2 = p2.matcher(inputLine);
            if(m2.matches()) {
                eDomain = m2.group(1);
                } else {
                eDomain = "n/a";
            }
        System.out.println(p2+" "+m2+" "+eDomain);
    }
}

And the results when I run it.

(\b@.*\b) java.util.regex.Matcher[pattern=(\b@.*\b) region=0,49 lastmatch=] n/a

All of my problems have been related to the what follows the @ being searched as a literal instead of a pattern (e.g., looking for .* rather than any and all characters). I can’t find references to @ being a control character, so I don’t think I need to escape out.

There are no similar examples in Oracle’s java tutorials or documentation, SO, nor any of the online resources I checked out; I’ve been unable to find other samples of how people have handled this. Like I said, I’m fairly new with regex, but this looks to me like it should be working to me. What am I missing?

  • 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-09T08:02:33+00:00Added an answer on June 9, 2026 at 8:02 am

    Java won’t treat @ as a word character – thus there is no word boundary at the start of your address. You could replace the word boundary with a simple whitespace match:

    "\s(@.+?)\b"
    

    (Or "\\s(@.+?)\\b" since this is Java) should do the trick. It looks for whitespace followed by @ and matches until the next word boundary.

    Edit: Oops, ., just like @, isn’t a word character (duh). Use

    "\\s(@.+?)(?:\\s|$)"
    

    to match until the next whitespace or EOF. (?:\\s|$) is a non-capturing group that will match any whitespace or end of input.

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

Sidebar

Related Questions

So I have file that with multiple line that look like this (space delimiter
I have a File that COntains Strings in This Format: ACHMU)][2:s,161,(ACH Payment Sys Menus
I have a file that contains this <!-- CordovaVersion --> I want to replace
I have a file that looks like: 1 1 C C 1.9873 2.347 3.88776
I have a file that has the following format: 12345 TAB_HERE Name : The
I have a file that can be any thing like ZIP, RAR, txt, CSV,
I have a file that I need to parse into an array but I
I have a file that I want to import into Microsoft Dynamics CRM 2011
I have a file that looks like: SECTION1 id name sub section1 sub section2
I have a file that contain huge number of net names. I would like

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.