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?

lcpr_phoenix
  • 373
  • 4
  • 15
  • why not starting learning regex then? – Fermat's Little Student Nov 04 '17 at 03:29
  • `hostmaster.whatsapp.com` is also URL. Is there any pattern for your URL ? – Shubhendu Pramanik Nov 04 '17 at 03: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. – CS_noob Nov 04 '17 at 03:36
  • the pattern can be any kind of URL, like: www.google.com, stackoverflow.com, https://github.com, asdf.ru, and etc. the most important thing is the dots who separate the domain and the host. – lcpr_phoenix Nov 04 '17 at 03:40

1 Answers1

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

Buddhi
  • 839
  • 10
  • 15