Code:
replace(/(\d *)x( *\d)/g, '$1×$2');
Let's break it down:
\d * - matches any occurrence of a single digit followed by 0 or more spaces.
Making it (\d *) means that the Regular Expression Object will store a reference to this match, as it is the first stored reference, it will later be accessible as $1.
The x matches a literal lowercase x character. Since there are no parentheses, it will not be stored.
( *\d) - is similar to the first part, only now matches 0 or more spaces followed by a digit and stores that as $2.
So, in something like:
255 x 150
it will match:
5 x 1
and replace it with:
5 × 1
Bookmarks