0

I have a String like this:

.........e1.whatsapp.net..............>.ns1.p13.dynect..hostmaster.whatsapp.com.x:a>.......X..:....

And I need to extract the first URL:

e1.whatsapp.net

I was trying with the solution in this post but not working for me, maybe because the amount of dots. Maybe if I try with another pattern regex, but I know nothing about "regex".

Any sugestion?

4
  • why not starting learning regex then? Commented Nov 4, 2017 at 3:29
  • hostmaster.whatsapp.com is also URL. Is there any pattern for your URL ? Commented Nov 4, 2017 at 3:32
  • Try to temporarily replace >1 number of dots (.) by some character that's not in regex like > and apply the same regex removing \\b(https?|ftp|file):// since your URLs don't have https etc before the address. Commented Nov 4, 2017 at 3:36
  • the pattern can be any kind of URL, like: www.google.com, stackoverflow.com, github.com, asdf.ru, and etc. the most important thing is the dots who separate the domain and the host. Commented Nov 4, 2017 at 3:40

1 Answer 1

0

This code below may help you to extract the email with using regex.

class StringSeperator {

  public static void main(String args[]){
    String urlString = ".........e1.whatsapp.net..............>.ns1.p13.dynect..hostmaster.whatsapp.com.x:a>.......X..:....";
    String array[] = urlString.split("\\.\\.+"); 
    System.out.println(array[1]);
  }
}

Here I use regex as \\.\\.+ which means two or more dots. The string split using two or more dots.

If I further explain about regex. Here I use \\. for depicting the dot and use + for saying one or more occurrences of a dots. For more details about Java regex please follow below link.

https://www.tutorialspoint.com/java/java_regular_expressions.htm

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.