“I have this text below, I would like to identify item name and amount for each”. Am not able to get the desired output using the code below. The code should disregard spaces and whether x is upper or lowercase for each line.
"The actual text is Rice Beef
Milk
20 27
× 200
Soda
Ugali
X
15
+ Chapo
X
65"
What i tried but can’t get a matching pattern
fun parseText(text: String) {
Log.d("crop-------", "initall: The actual text is ${text}")
val sales = mutableListOf<Sale>()
//val regex = Regex("(.+) = (\d+)")
val regex = Regex("(\w+\s*)[Xx×](\s*\d+)", RegexOption.IGNORE_CASE)
text.lines().forEach { line ->
regex.findAll(line).forEach { matchResult ->
val (name, amount) = matchResult.destructured
sales.add(Sale(name.trim(), amount.toInt()))
}
}
salesAdapter.submitList(sales)
}