Hi, i want to know how to write the regular expression in javascirpt please help me give a simple exaple with details i mean the source code(i am using asp.net and c# language) thank u
You may want to refer concise article on : www.regular-expressions.info/javascript.html
First you need to understand the concept of regular expression. Once you know what regex is, writing them in any language is not difficult.
You can read these
String and Regular Expression methods
If you are interested in buying a regex book then this one is good
You can write a regular expression literal enclosed in slashes like this:
var re = /\w+/;
That matches something that contains one or more word characters.
You can also create a regular expression from a string:
var re = new RegExp("\\w+");
Notice that since that's a string literal, I have to double the backslash to escape its special meaning for strings.
There are tons of examples online for using JavaScript's RegExp object. Start with this.
Here is a simple example of creating a RegExp and then using it to determine whether there is at least one occurrence of the word "dog" in the passed string.
var myString = "I wish all dogs were brown.";
var myRegExp = new RegExp("dog");
var containsDog = myRegExp.test(myString);
In this example, containsDog would be 'true'.
I think the following articles from Mozilla Dev Center are a very good introduction:
This should also work:
var myString = "I wish all dogs were brown.";
if (myString.match(/dog/i))
{
//do something
}