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

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -