JavaScript tutorial-string pattern

Regular Expression

String pattern

Writing a simple string pattern

Now let write a simple string pattern to split the following string object to an array--starr:

var st="JavaScript is powerful web scripting language";

This string can be split by the space character. Therefore, string pattern should be:

var stpat=/ /;

Then by supplying this string pattern as an argument of the split() method you will get an array of strings.

var starr=st.split(stpat);

Now you see the complete example code as shown below:

<title>Regular Expression-a simple string pattern</title>

<script language="JavaScript" type="text/javascript">

var st="JavaScript is powerful web scripting language";
var stpat=/ /;
var starr=st.split(stpat);
var i;




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.