Geo Geo - 1 year ago 77
Ruby Question

How can I tokenize this with a regex?

Suppose I have strings like the following :


I know how to tokenize the camel-case ones, except the "DVDPlayer" and "CDPlayer". I know I could tokenize them manually, but maybe you can show me a regex that can handle all the cases?

the expected tokens are :

OneTwo -> One Two
CDPlayer -> CD Player
DVDPlayer -> DVD Player

Answer Source

Look at my answer on the question, .NET - How can you split a “caps” delimited string into an array?.

The regex looks like this:


It can be modified slightly to allow searching for camel-cased tokens, by replacing the $ with \b:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download