The replace() method every JavaScript string supports can replace text. It searches for a regular expression and replaces the match with another string. Within this replacement string, you can back-reference submatches. $0 points to the first match, $1 references the first submatch (within parentheses), $2 the second submatch, and so on. The preceding code searches for the city, state, and zip code elements and then rearranges them. The result is "46240 Indianapolis, IN". |