Regex to identify functions in expression

javascript regex test
regex match
regular expression examples
regex capture function arguments
regex match function name
regex match function python
regex tutorial
regex engine

I have a text which is expression formula something like


like add() , sin() , add_days(), now()

Is there any way to identify functions using regular expression in javascript and replace with span tag to apply to style.

Final text needed :

<span> add  (</span>1,2<span>)</span>+<span>sin(</span>90<span>)</span>+1/2+<span>add_days(</span><span>now(</span><span>)</span>,30<span>)</span>+data
var input = "add (1,2)+sin(90)+1/2+add_days(now(),30)";

var output = "<span> add </span> (1,2)+<span>sin</span>(90)+1/2+<span>add_days</span>(<span>now</span>(),30)";

var out = input.replace(/(\s?[a-z_]+\s?)/ig, "<span>$1</span>");


add (1,2)+sin(90)+1/2+add_days(now(),30)
<span> add </span> (1,2)+<span>sin</span>(90)+1/2+<span>add_days</span>(<span>now</span>(),30)
<span>add </span>(1,2)+<span>sin</span>(90)+1/2+<span>add_days</span>(<span>now</span>(),30)

Regex for matching Functions and Capturing their Arguments , Matches(expr); // Parse the expression for functions. foreach (Match match in funcs) {  If you are unfamiliar with RegEx, you may want to view the Creating Regular Expressions lesson, referenced below. Estimated Time: ~7 Minutes. Description: Use the RegEx_Replace function to replace string values matching your target; Use the RegEx_Match function to identify string values matching your target

if you could list all the math functions used in your document, this could work out for you.

var MATH_FUNCTIONS = ['add', 'sin', 'add_days', 'now'];

var input = 'add(1,2)+sin(90)+1/2+add_days(now(),30)';

var regex = new RegExp('(\\b'+MATH_FUNCTIONS.join('\\b|')+'\\b)', 'gm');

input.replace(regex, '<span>$1</span>');

Regular expressions, Regular expressions are patterns used to match character Use the constructor function when you know the regular expression pattern will be  Add VBA reference to the Regular Expressions library (shamelessly copied from Portland Runners++ answer): Click on Tools-> References (please excuse the german screenshot) Find Microsoft VBScript Regular Expressions 5.5 in the list and tick the checkbox next to it. Click OK. Click on Insert Module.

Using replace with $& solves the problem. $& helps to get matched characters in case of multiple groups.

var input = "add (1,2)+sin(90)+1/2+add_days(now(),30)+data";
var out = input.replace(/(?:(\s?[a-z_]+\s?\()|(\)))/ig, "<span>$&</span>");


//<span>add (</span>1,2<span>)</span>+<span>sin(</span>90<span>)</span>+1/2+<span>add_days(</span><span>now(</span><span>)</span>,30<span>)</span>+data

Regular Expression Functions, The regular expression syntax allows you to precisely define the pattern used to match strings, giving you much greater control than wildcard matching used in the  Match Regex is one of the functions used to check the pattern of the particular data attribute. Mainly this is used to validate the Email address and Phone numbers. The following is the analysis which describes how to validate a phone number Using Match Regex function in SAP Information Steward Tool. Step 1: Create a Rule named PHONE_NUMBER

REGEX: Matching a String to a Regular Expression, The REGEX function matches a string to a regular expression and returns true (1) if it matches and false (0) if it does not match. A regular expression is a  A regular expression is a pattern that the regular expression engine attempts to match in input text. A pattern consists of one or more character literals, operators, or constructs. For a brief introduction, see .NET Regular Expressions. Each section in this quick reference lists a particular category

REGEXFIND( ) function, The REGEXFIND( ) function uses a regular expression to search data search goals using simpler Analytics search functions such as FIND( )  A regular expression, regex or regexp (sometimes called a rational expression) is a sequence of characters that define a search pattern. Usually such patterns are used by string searching algorithms for "find" or "find and replace" operations on strings, or for input validation.

Regexp Functions (Guile Reference Manual), Each time string-match is called, it must compile its pattern argument into a regular expression structure. This operation is expensive, which makes string-​match  A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern. They can be used to search, edit, or manipulate text and data. The java.util.regex package primarily consists of the following three classes − Pattern Class − A Pattern object is a compiled representation of a regular expression. The Pattern class provides no public constructors.

  • What have you tried so far? (replace...?)
  • what will be my regular expression in replace ? My function will have alphabet and underscore character only@Stuart
  • Can we do something like…
  • It also appends if variable is added like var input = "add (1,2)+sin(90)+1/2+add_days(now(),30)+data";
  • data is variable should not be appended and function has brackets
  • Can we add brackets also to the regular expression and on replace one character ( with span closing tag
  • I have the same output that you expected, if you need another one, please change the original post and write a better example
  • I don't know the list of function possible
  • @Sumeet you are going to need the list of possible functions if you are to replace them!
  • maybe you have another way to locate these expression formulas inside the html? like a specific css class?