AJAX Made Easy - Learn AJAX



AJAX-Tips Tutorials

 
Home AJAX-Tips
 

Effectively Using RegExp in Ajax

 

RegExp or Regular Expressions is a very smart tool that could be used in JavaScript which could eventually be implemented in an Ajax based application. Regular Expressions has been integrated in JavaScript since its 1.2 version and could be supported by browsers since IE4.


Its counterpart in Adobe, ActionScript 3 also has the same integration since it was implemented by ECMA in its 262 update. JavaScript’s support for Regular Expressions has broadened significantly especially when each functions and objects in Ajax have a built-in recognition for this type of function. You’ll be able to build a simple Ajax based application but has greater functionality once they are implemented.


Advantages of Regular Expressions

The main role of Regular Expressions is its ability to bind itself to different data and functions faster. Developers should be able to target the data they want and function they need by directly pointing out the data. But this requires a very long code and it could even be longer if the object has to deal with another function. Instead of using a single function and data with a very long code, Regular Expressions could be used so that these data could be loaded in the object faster.


Instead of longer codes, Regular Expressions uses a different signs to effectively instruct the browser to execute a certain function. Forward and backslash are now being used in regular expressions. This could be a little bit more complicated and it will require practice but it could be at the developer’s advantage since it uses shorter codes and simpler commands.


Tips in Using Regular Expressions

New Instance over Direct Usage – Regular Expressions is already integrated in each object that a developer could just use this function directly to an object. Although it could happen, it will slow down the execution of the object since browsers will have to read them all first before executing them. A smart alternative is to build a different instance just below the object. This will ensure that the browser will read the object first and apply the functions from regular expressions later. This method is faster for the browser as it will read the object and instance one by one.


Avoid literal strings – When using a constructor, do not use literal strings. A constructor could save you time and effort on how to build Regular Expressions and other functions for your Ajax based application, but you have to limit or even avoid using literal strings. Literal strings will inhibit the use of backslash which is a very important part of any Regular Expression.


Efficient use of capturing parenthesis – One of the best features of regular expressions is its ability to capture functions and object even in different cases. But this should never be abused if the developer wants to have an efficient Ajax based application.


Regular expressions could easily place an application in a better position and this should never be avoided by the developer. However, careful consideration especially in capturing parenthesis has to be remembered to increase the efficiency of regular expressions.



Read Next: Best Practices for Layout in Ajax



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links