How to replace asterisk symbols (*) with bold tags to denote important words and phrases?

1

I have a document of nearly 20K lines. Many (but not all) of the lines use asterisk symbols to denote important words and phrases.

Example:

What kind of *vegetable* is it?
You are *best?!*
I hope I am not late.
All *the "good"* shows are *no longer* broadcasting.

I would like to replace the asterisk symbols with html bold tags. E.g. so it looks like this:

What kind of <b>vegetable</b> is it?
You are <b>best?!</b>  
I hope I am not late.
All <b>the "good"</b> shows are <b>no longer</b> broadcasting.

What's the best way of doing this? I can't just do a find and replace, because it won’t insert the appropriate closing </b> tag when required.

My document is currently in a spreadsheet but I can import it into any other format, so long as it can be returned to the spreadsheet.

My environment: I am using Apple Numbers on Mac OSX. But I am happy to install another application. I also have Windows on Virtual Box but would prefer to avoid using that if possible.

update

One more question: If I wanted to create a new column that had just words in asterisk symbols prefixed with the word "Emphasize"" and nothing else, would that be possible with plugin? If so, how?

Example:

  • What kind of vegetable is it?
    becomes
    Emphasize: vegetable
  • All the "good" shows are no longer broadcasting.
    becomes
    Emphasize: the good, Emphasize: no longer.

big_smile

Posted 2018-04-24T08:05:21.443

Reputation: 331

3Do you use Windows or Linux? Excel, OpenOffice, LibreOffice, something else? Please [edit] your question. – gronostaj – 2018-04-24T08:06:51.150

Answers

2

In Excel you can use free RegEx Find Replace add-in to perform a replace using regular expressions:

enter image description here

I'm not affiliated with that add-in in any way, just use it as I find it useful.


Update

The expression should work also in other tools with regex support (https://regex101.com/r/928oKB/1)

If your entries may contain other characters too, then just change "Find what" expression to:
\*([^*]+)\*
It'll capture everything between two *

(you can test it here)

Update:

Yes, you can add "Emphasize" too, however that is easier with a helper column.

  • Formula for the helper column:
    =RegExReplace(A1,"[^*]*\*([^*]+)\*[^*]*",", Emphasize: $1")
  • Formula for the result:
    =RIGHT(B1,LEN(B1)-2)

enter image description here

Máté Juhász

Posted 2018-04-24T08:05:21.443

Reputation: 16 807

Will that regex command in your screenshot work in any Regex editor or is it for excel only. Thanks! – big_smile – 2018-04-24T08:55:36.690

1But it doesn't correctly find a span which contains e.g. punctuation; the regex in the screen shot only covers alphabetics and spaces. – tripleee – 2018-04-24T09:11:29.090

@MátéJuhász that might be a problem for me as some of my spans do have punctuation. (I better update my question with this!) – big_smile – 2018-04-24T09:19:16.623

@MátéJuhász Thanks, I got the plugin working and your expression works perfectly. One more question: If I wanted to create a new column that had just words in asterisk symbols prefixed with the word "Emphasize"" and nothing else, would that be possible with plugin. If so, how. Example: What kind of *vegetable* is it? becomes Emphasize: vegetable in the new column. All *the "good"* shows are *no longer* broadcasting. becomes Emphasize: the good, Emphasize: no longer. Thanks for any help you can offer. – big_smile – 2018-04-26T18:23:52.393