20 lines
491 B
Kotlin
20 lines
491 B
Kotlin
package core.utils
|
|
|
|
data class LinkMetadata(
|
|
val url: String,
|
|
val title: String? = null,
|
|
val description: String? = null,
|
|
val imageUrl: String? = null
|
|
)
|
|
|
|
object LinkParser {
|
|
private val URL_PATTERN = Regex(
|
|
"(?:^|[\\s])((https?://)[\\w-]+(\\.[\\w-]+)+\\.?(:\\d+)?(/[\\w- ./?%&=]*)?)",
|
|
RegexOption.IGNORE_CASE
|
|
)
|
|
|
|
fun findLinks(text: String): List<String> {
|
|
return URL_PATTERN.findAll(text).map { it.groupValues[1].trim() }.toList()
|
|
}
|
|
}
|