'Increment bracketed numbers in blob of text

I'm wondering if and how this can be done using Dart. Basically we have a list of ingredients and want to give the user the ability to increment (or decrement) the serving size. When this happens, we need to change the numbers in brackets []. We also need to gracefully handle formatted fractions.

Here's an example of the text:

Bean Bowl Base
[2], 15 oz cans of black beans, rinsed and drained
[1 1/2] cups frozen fire roasted corn, thawed
[1] red bell pepper, diced
[1/4] cup diced red onion, about half a small onion
[1] cup cherry tomatoes, halved
[1/4] cup fresh cilantro, minced
Tortillas or Tortilla chips for serving

Lime Dressing
Juice and zest of [2] limes
[2] tbsp extra virgin olive oil
[2] tbsp apple cider vinegar or white wine vinegar
[1] tbsp maple syrup or agave, adjust amount based on preference
[2] cloves garlic, crushed
[1/2] tsp ground cumin
[1–2] tsp smoked paprika, chipotle powder or chili powder
[1/4] tsp salt or more to taste

My thoughts are to:

  1. Split the text at every \n
  2. Map each line, looking for at most one [] to update

I'm not sure how to accomplish the (2).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source