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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:51:04+00:00 2026-05-26T17:51:04+00:00

i have pattern: host=([a-z0-9./:]*) it’s find for me host address. And i have content

  • 0

i have pattern:

host=([a-z0-9./:]*)

it’s find for me host address. And i have content

host=http//:sdf3452.domain.com/

And my code is:

    Matcher m;
    Pattern hostP = Pattern.compile("host=([a-z0-9./:]*)");
    m=hostP.matcher(content);//string 1
    String match = m.group();//string 2 
    Log.i("host", ""+hostP.matcher(content).find());

if i delete string 1 and 2 i see true in logcat. If left as is I got exception nothing found.
I’ve tried all kinds of pattern. Through debug looked m variable, finds no match. Please teach me use reg exp!

  • 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-26T17:51:05+00:00Added an answer on May 26, 2026 at 5:51 pm

    Before you group() a match, you need to invoke find().

    Try it like this:

    Pattern hostP = Pattern.compile("host=([a-z0-9./:]*)");
    Matcher m = hostP.matcher(content);
    
    if(m.find()) {
      String match = m.group();
      // ... 
    }
    

    EDIT

    and a little demo that shows what each match-group contains:

    Pattern p = Pattern.compile("host=([a-z0-9./:]*)");
    Matcher m = p.matcher("host=http://sdf3452.domain.com/");
    if (m.find()) {
      for(int i = 0; i <= m.groupCount(); i++) {
        System.out.printf("m.group(%d) = '%s'\n", i, m.group(i));
      }
    }
    

    which will print:

    m.group(0) = 'host=http://sdf3452.domain.com/'
    m.group(1) = 'http://sdf3452.domain.com/'

    As you can see, group(0), which is the same as group(), contains what the entire pattern matches.

    But realize that a URL can contain much more than what your defined in [a-z0-9./:]*!

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

Sidebar

Related Questions

I need help with re module. I have pattern: pattern = re.compile('''first_condition\((.*)\) extra_condition\((.*)\) testing\((.*)\)
I have the following pattern: preg_match( /^(.*?\/wp-content\/)([^\?]+)(.*)$/, $src, $src_bits ); Now I want to
I've looked all over and have yet to find a single solution to address
Old Working Pattern until the website changes how it host files. http[s]?://[0-9a-z_.-]+\.[a-z]{2,4}[:0-9]*/([0-9a-z_./-])*[0-9a-z _.-](?:jpg|bmp|gif|png)+ I
I have pattern like below hi hello hallo greetings salutations no more hello for
I have this pattern to get cause-effect relationship between noun phrases in a sentence:
I have a pattern (.png image 4x4px) and have to fill the layout with
I have this pattern: ~^([a-z0-9]+[a-z0-9-]+[a-z0-9]+\.([a-z]+)(\.[a-z]+)?)$~i It will match the following: xxx.xxx or xxx.xxx.xxx (number
I have this pattern written ^.*\.(?!jpg$|png$).+$ However there is a problem - this pattern
Ok so if I have this pattern: ab&bc&cd&de&ef And I need to replace all

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.