+ Start a Discussion
JamesSSJamesSS 

regex returns null in inside of javascript function?

I want to get all strings length startswith "{!" and endswith "}" in given string(it will take from apex:input text area value).

refer exact output for my jsfiddle link
http://jsfiddle.net/XzS5V/5/


I am using regex for get this output.but it always reyurn null

My code:
<apex:page standardController="Account">
  <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" />

 
  <apex:form >
      <apex:inputTextarea styleClass="myFld" style="width: 447px;height:300px;"/>
  </apex:form>
<script type="text/javascript">
  $(".myFld").keyup(function() {      
            var myFieldValue = $(this).val();
            calculateStringCounts(myFieldValue);
  });
   function calculateStringCounts(myField){
       //var filter = /\{\!\w+\}/g;
       //var filter = /([A-Z])\w+/g;
       var filter =/\{\!\w+\}+/g;
       var newArr = myField.match(filter);
       alert(newArr.length);
       return false;
    }
</script>
</apex:page>
VikashVikash (Salesforce Developers) 
Hi,

Unfortunately I am not able to find any regex function in your code. Please refer the sample code below to use regex in Javascript

<apex:inputText id="searchText" value="{!searchText}" onmousemove="checkingstring(this)"/>

<script>
function checkingstring(searchText){
var pattern = "([a-zA-Z](2)[0-9](4)-[0-9](5))";  /// is it correct
var regexp = new System.Text.RegularExpressions.Regex(pattern);
var userInput = "(123) 555-1243";
if (!regexp.IsMatch($component.searchText))
{
  alert("The syntax is always as follows: AANNNN-NNNNN (A= Alpha/Letter; N= Number) i.e.FL0301-12345</b>"); 

}
}
</script>

----or-----

<apex:page >
  <script type="text/javascript">
      function testRegex() {
           
            var str = 'Custom $955.45';
            var mat = str.match(/\$(.*)/g);
            alert(mat[0]);
           
        }
       
        window.onload = function() {
            testRegex();
        }
  </script>
</apex:page>

Thanks
Vikash_SFDC