edi233:
Tengo dos cadenas:
http://porter.com/request/.*
y
http://porter.com/request/tokenId
Quiero comprobar si las primeras partes: http://porter.com/request
son los mismos en ambos y comprobar si tokenId
no es nulo, ya que en algunos casos podría ser única http://porter.com/request/
. Yo uso algo así:
override fun validate(pair: Pair<URI, URI>): Boolean {
val uri = pair.first.path.split("/").dropLast(1).filter { it.isNotBlank() }.joinToString("")
val uriIntent = pair.second.path.split("/").dropLast(1).filter { it.isNotBlank() }.joinToString("")
val asd = pair.second.path.split("/").filter { it.isNotBlank() }.last().isNotBlank()
return uri == uriIntent && asd
}
pero esto no está funcionando para último caso: http://porter.com/request/
¿Alguna idea?
GensaGames:
final String regex = "(http://porter.com/request/).+";
/**
* Below code will return false
* since, URL doesn't have last path
*/
final String yourUrl = "http://porter.com/request/.*";
final boolean valid = yourUrl.matches(regex)
/**
* Same (will return false), as ex. above
*/
final String yourUrl = "http://porter.com/request/*";
final boolean valid = yourUrl.matches(regex)
/**
* This will return true. Link is Ok.
*/
final String yourUrl = "http://porter.com/request/tokenId";
final boolean valid = yourUrl.matches(regex)