regex - using regular expression pattern replace to convert cents to dollars -
am new regex and, have situation store price in cents need search them using dollar equivalent. trying write pattern replacer converts cents dollars (basically divide 100)
eg:
2349 -> 23.49 18 -> .18
any appreciated
there should easier ways of doing this.
regex:
\b(?\d*?)(?\d{1,2})\b
first group $ , second group cents.
replace regex:
${dollar}.${cent}
this search numbers (any length) in string , split in $ , cents.
explain:
\b : word boundry
\d : digit
*? : lazy select (as few matches possible)
{1,2} : match 1 or 2 characters. fill before lazy *? selection
( ) : grouping
Comments
Post a Comment