Regular Expressions4. Spliting Matches |
|
Join the DiscussionMore of this FeatureIntroduction Pattern Matching Ignore Case and Global Replacing Matches The split method available on string objects can also be used with regular expressions. This allows you to be a bit more flexible in the delimiters that you use within a text string that is typed in when you want to break it up into individual entries in an array. For example:
var myString = 'The boy sat on the log next to the
tree.';
var re = / /; var word = myString.split(re); In this example, myString is split up into individual words with each word being stored as a separate entry in the word array. Of cous=rse the same effect as with this simple regular expression can be achieved by just testing for a single space using mystring.split(' '); but there is a lot more to regular expressions than we have seen so far. Up until now we have been looking at how to define regular expressions and use them. In the tutorials that follow we will look at how we can use characters and patterns that have special meanings that will really extend the functionality of these simple tests that we have looked at so far and allow us to achieve some really sophisticated processing in just a few statements. |

