My original thinking was that this would work
grep -w '\*.*\*' /path/file-name
This produces some good hits but it doesn't respect the word option. I get whole lines. For example, like this
[bold]*way* to the store to buy some groceries and *then*[bold]
and I want to get this
[bold]*way*[bold] to the store to buy some groceries and [bold]*then*[bold]
Another one I get is this, which I thought wouldn't appear because it has spaces (which should disqualify it because I want only words or stuff separated by spaces)
* * *
You need to make the match non-greedy: in a basic (BRE) or extended (ERE) regular expression you can enforce that by using an exclusive character set
[^*]
in place of the inclusive.*
i.e.or
If you a prefer perl-compatible regex, that has an explicit non-greedy modifier
?