Friday, September 14, 2007

JavaScript Objects: Regular Expressions

Regular expressions are arrangements of characters that form a pattern that can then be used against strings to find matches, make replacements, or locate specific substrings.

This is the first time that I didn't have to learn a thing by myself. Finally learnt something from school and it's only a month before I really have to say goodbye to the school days.

The following JavaScript snippets are posted to my Pownce account during an actual classroom discussion and examination over an unauthorized internet access.

<script>
var re = /JS*/ig;
var str = "cfdsJS *(&YJSjs 888JS";
var resultArray = re.exec(str);

while(resultArray){
document.writeln(resultArray[0]);
resultArray = re.exec(str);
}

document.write("<br />");

var regExp = /\s\*/g;
var srt = "This *is *a *text *string";
var resultString = srt.replace(regExp,'-');
document.writeln(resultString);
</script>

http://pownce.com/parakatis/notes/711834/

No comments:

Recent posts



Search




Candies

Powered by FeedBurner
View blog authority Ranking.PinoyBlogosphere.Com Creative Commons License
[ You've reached the bottom. Scroll back to top ]