edi233 :
I have two strings:
http://porter.com/request/.*
and
http://porter.com/request/tokenId
I want to check if first parts: http://porter.com/request
are the same in both and check if tokenId
is not null, because in some cases it could be only http://porter.com/request/
. I use something like that:
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
}
but this is not working for last case: http://porter.com/request/
Any ideas?
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)