PDA

View Full Version : Use Regex to Format String



swaggerbox
02-01-2013, 05:29 AM
I'm using Word 2010. Is it possible to format a certain string using Regex?

See example input below:
2.2 parts of yellow ink, 2.5 parts of black ink and 3 parts of white ink

and preferred output below:
yellow ink (2.2), black ink (2.5) and white ink (3)

any help would be greatly appreciated.

macropod
02-01-2013, 05:19 PM
This isn't so much a case of formatting as re-structuring. Try a wildcard Find/Replace where:
Find = (<[0-9.]{1,}>) part[s ]{1,2}of (<*> ink)
Replace = \2 (\1)
No vba required. If you want to have it as a macro, though, simply switch on the macro recorder and record the Find/Replace.

swaggerbox
02-02-2013, 03:45 PM
thanks paul. i didn't know this could be done without vba.