Split C char * for reference to spreadsheet table

Summary: I have a parser that grabs cell references using the following regex

"$"? {Letter} {1,2} "$"? {Digit} {1,3}

I can't seem to find an elegant way to split the resulting char * into my string and column components.

ex. split a1 into a and 1 or split $ aa $ 4 into fixed_col fixed line 4

Any help is appreciated.

+1


source to share


1 answer


Are you using a regex library? If so, then it supports accessing the grouped parts of the regex, for example:

("$"?)({letter})({1,2})("$"?)({digit}{1,3})

      



(This article shows a technique using the .NET regex library)

If that's not an option, then creating a simple state machine will work well and be easy to maintain and test.

+1


source







All Articles