You are currently viewing the BOOK: Beginning Regular Expressions section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
patterns are supposed to go trough a whole text. often you will find yourself wanting several matches from the same document. For example you want to find all occurences off a misspelled word, to correct it. Basically, if you want to limit matching to a string of three digits only, you could do the following: /^\d{3}$/
If you only want to find 3 digit numbers in a longer text, use: /(?<!\d)\d{3}(?!\d)/
If they are just separated by whitespace, use /(?<=\s)\d{3}(?=\s)/
There is a quite good explanation about regex in Professional javascript for web developers by wrox.