This is a pretty simple script to solve a small inconveinece for which I could find no convenient solution on the internet. It's based on this comment flutter/flutter#41955 (comment) in the Flutter GitHub page. Unfortunately, I'm no good at Perl. When I couldn't get it to work, I decided to reuse the regex pattern and create a python script that is easily readable and modifiable.
To use this, first make sure you have Python 3 installed. Next, simply place the python script in the root folder of your project (i.e. the folder that holds your pubspec.yaml file) and configure it as a pre-build task. If you're using VS Code, you can use the two included json files as an example to modify your launch.json and tasks.json files found in the .vscode folder. If you don't already have a tasks.json file, you can drop mine straight into your project's .vscode folder, you may need to change "python increment_build.py"
to something like "python3 increment_build.py"
to accommodate your particular Python setup.