Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a way to create a JavaScript look behind that has worked in all cases I needed.</p> <p>This is an example. One can do many more complex and flexible things.</p> <p>The main point here is that in some cases, it is possible to create a RegExp non-capturing prefix (look behind) construct in JavaScript .</p> <p>This example is designed to extract all fields that are surrounded by braces '{...}'. The braces are not returned with the field.</p> <p>This is just an example to show the idea at work not necessarily a prelude to an application.</p> <pre><code> function testGetSingleRepeatedCharacterInBraces() { var leadingHtmlSpaces = '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;' ; // The '(?:\b|\B(?={))' acts as a prefix non-capturing group. // That is, this works (?:\b|\B(?=WhateverYouLike)) var regex = /(?:\b|\B(?={))(([0-9a-zA-Z_])\2{4})(?=})/g ; var string = '' ; string = 'Message has no fields' ; document.write( 'String =&gt; "' + string + '"&lt;br&gt;' + leadingHtmlSpaces + 'fields =&gt; ' + getMatchingFields( string, regex ) + '&lt;br&gt;' ) ; string = '{LLLLL}Message {11111}{22222} {ffffff}abc def{EEEEE} {_____} {4444} {666666} {55555}' ; document.write( 'String =&gt; "' + string + '"&lt;br&gt;' + leadingHtmlSpaces + 'fields =&gt; ' + getMatchingFields( string, regex ) + '&lt;br&gt;' ) ; } ; function getMatchingFields( stringToSearch, regex ) { var matches = stringToSearch.match( regex ) ; return matches ? matches : [] ; } ; Output: String =&gt; "Message has no fields" fields =&gt; String =&gt; "{LLLLL}Message {11111}{22222} {ffffff}abc def{EEEEE} {_____} {4444} {666666} {55555}" fields =&gt; LLLLL,11111,22222,EEEEE,_____,55555 </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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