I want to extract bell.com from these following input using Scala regex. I have tried a few variations without success.
"www.bell.com"
"bell.com"
"http://www.bell.com"
"https://www.bell.com"
"https://bell.com/about"
"https://www.bell.com?token=123"
This is my code but not working.
val pattern = """(?:([http|https]://)?)(?:(www\.)?)([A-Za-z0-9._%+-]+)[/]?(?:.*)""".r
url match {
case pattern(domain) =>
print(domain)
case _ => print("not found!")
}
EDIT: My regex is wrong. Thanks to @Tabo. This is correct one.
(?:https?://)?(?:www\.)?([A-Za-z0-9._%+-]+)/?.*