Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Highlight parts of text according to a given pattern
ResourceFunction["HighlightText"]["text",patt] highlights the substrings in "text" that match the string expression patt. | |
ResourceFunction["HighlightText"]["text",patt→col] highlights the strings matching patt using the background color col. | |
ResourceFunction["HighlightText"]["text",{p1→col1,p2→col2,…}] highlights each of the pi with color coli. | |
ResourceFunction["HighlightText"]["text",patt,n] highlights up to n occurrences of patt. |
"TrimmingThreshold" | None | the max number of characters to display around highlighted sections |
IgnoreCase | False | whether to treat lowercase and uppercase letters as equivalent |
"DefaultColor" | the default color to use when no color is explicitly given for a pattern |
Highlight part of some text:
In[1]:= |
Out[1]= |
Use a string pattern:
In[2]:= |
Out[2]= |
Highlight dates using DatePattern:
In[3]:= |
Out[3]= |
Provide a list of items to highlight:
In[4]:= |
Out[4]= |
Specify a color for highlighting:
In[5]:= |
Out[5]= |
Specify a different color for each pattern:
In[6]:= |
Out[6]= |
Font color is automatically chosen based on the highlight color:
In[7]:= |
Out[7]= |
Limit the number of items to highlight:
In[8]:= |
Out[8]= |
Change the default highlight color:
In[9]:= |
Out[9]= |
By default, pattern matching is case-sensitive:
In[10]:= |
Out[10]= |
Ignore case instead by setting IgnoreCase→True:
In[11]:= |
Out[11]= |
Only show text in the vicinity of highlighted areas:
In[12]:= |
Out[12]= |
Show more text:
In[13]:= |
Out[13]= |
Don’t trim any text:
In[14]:= |
Out[14]= |
If the original text does not have line breaks, the trimmed parts will appear inline:
In[15]:= |
Out[15]= |
If the original text has line breaks, the trimmed parts will each appear on their own line:
In[16]:= |
Out[16]= |
Search for a word in a large body of text:
In[17]:= |
Out[17]= |
The highlighting wraps tightly around text, so heights may not match:
In[18]:= |
Out[18]= |
Consecutive matches are grouped together and will have the same highlighting height:
In[19]:= |
Out[19]= |
Highlight the different writing scripts being used in a Japanese sentence:
In[20]:= |
Out[20]= |
Interactively highlight words based on the number of characters:
In[21]:= |
Out[21]= |
This work is licensed under a Creative Commons Attribution 4.0 International License