[ajug-members] Parsing Question

Ricardo Ferrer ricafeal at gmail.com
Mon Aug 21 16:46:27 EDT 2006


  Hi Christopher,

  Check if this is useful to you:

public class RegEx {

    public static void main(String args[]) {
        String patternStr = "\\.([^\\.]*?)\\.com";
        Pattern pattern = Pattern.compile(patternStr);

        String inputStr = "http://www.host.domain.com/site/index.htm";
        Matcher matcher = pattern.matcher(inputStr);
        boolean matchFound = matcher.find();
        if (matchFound) {
            String domain = matcher.group(1);
            System.out.println(domain);
        }
        else {
            // Not found, do something
        }

    }
}

Regards,
Ricardo

On 8/21/06, Christopher Fowler <cfowler at outpostsentinel.com> wrote:
>
> I need to parse the domain name out of strings that could be
> of any possible format.
>
> Formats include:
>
> http://www.domain.com/
> http://www.domain.com
> https://www.domain.com/
> www.domain.com
> www.host.domain.com
> http://www.domain.com/site/index.htm
>
> You can see it can very.  Is there a trick I can
> use with regex in the String class to extract the "domain.name"
>
>
>
> _______________________________________________
> ajug-members mailing list
> ajug-members at ajug.org
> http://www.ajug.org/mailman/listinfo/ajug-members
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.ajug.org/pipermail/ajug-members/attachments/20060821/76c40472/attachment.html 


More information about the ajug-members mailing list