Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In Javascript:</p> <pre><code>var pattern = '\\[record:([a-zA-Z0-9]+)\\]'; var records = new RegExp(pattern, 'g'); var extract = new RegExp(pattern); var string = "Customer [record:CustomerID] from [record:CityID] is of type [record:TypeID]" var matches = string.match(records); console.log(matches); &gt; [ '[record:CustomerID]', '[record:CityID]', '[record:TypeID]' ] var records = []; for (var i=0; i&lt;matches.length; i++) { var match = matches[i].match(extract); records.push(match[1]); } console.log(records) &gt; [ 'CustomerID', 'CityID', 'TypeID' ] </code></pre> <p>Possibly not the most concise solution, but clean and (hopefully) intelligible.</p> <ul> <li>the square brackets that should not be treated specially are escaped by placing <code>\</code> in front of them</li> <li>the group to be extracted are wrapped in <code>()</code>, forming a regexp group/subpattern</li> <li>the pattern <code>[a-zA-Z0-9]+</code> means "match a string of letters (upper or lower case) or numbers" and the <code>+</code> specifies "of length one or more". A <code>*</code> here would mean "of length 0 or more".</li> </ul> <p>Here I am using two regular expressions, based on the same pattern. They are compiled with different options: the <code>g</code> flag tells the regex to look for all matches in the string. With this flag, we don't get the groups that matched with the results, just the whole string that matched. The second regex is compiled without the <code>g</code> flag, so we can use it to extract the matched group.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload