How can I avoid app names in inapp item titles returned from Google Play getSkuDetails?

That is the way it is. I mean even I didn't like it, obviously user knows that he is buying from the app but I think Google is going to reply it in this way only


As no one has replied with an actual regex pattern to match the app name in parentheses in the SKU title I thought I just post the code here for further reference:

// matches the last text surrounded by parentheses at the end of the SKU title
val skuTitleAppNameRegex = """(?> \(.+?\))$""".toRegex()

val titleWithoutAppName = skuDetails.title.replace(skuTitleAppNameRegex, "")

The regex is as strict as possible to allow for additional text in parentheses within your SKU title without removing it as well (e.g. SKU titles like Premium (Subscription) would stay as they are). The only thing you should avoid is parentheses in your app name, but with a little tweaking of the regex you could work around that as well.

As regexes are notoriously expensive to build it is advisable to store it in a field and avoid constructing them each time over when you are parsing your SKUs.


Adapting @ubuntudroid answer to Java, I made it work like this:

String skuTitleAppNameRegex = "(?> \\(.+?\\))$";
Pattern p = Pattern.compile(skuTitleAppNameRegex, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(skuDetails.getTitle());
String titleWithoutAppName = m.replaceAll("");