View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
M. Authement M. Authement is offline
external usenet poster
 
Posts: 94
Default Regular Expression for cell address

Thanks Ron.

Does that mean that the potential cell address MUST be preceeded by one of
the characters in the first part of the expression in order for the rest of
the expression to be true (found in a string)?

Also, any thoughts on making the row number expression more robust?

"Ron Rosenfeld" wrote in message
...
On Tue, 2 Jan 2007 12:43:13 -0500, "M. Authement"
wrote:

Can someone explain this regular expression to me? I found it in some VBA
code for finding/altering a cell address within a string. I put spaces in
to break the expression apart into the parts (I think) I understand.

(?:[\^\])-/+*:,="[(]) (\$?) ([A-Z]{1,2}) (\$?) (\d{1,5}) ([^\d]|$)

The second and fourth part are the optional absolute/relative dollar sign,
the third part is the one or two character column, and the fifth part is
the
1 to 5 digit row number.

What are the first and last parts of this expression?

Is there a more robust way to designate the row number as 1-65536?

What about the column designation? I was thinking something like
([A-Za-z]|[A-Za-z][A-Za-z]|[Ii][A-Va-v]). This allows for lower case
letters and avoids the possibility of columns greater than IV.

I am new to regular expressions, having read an online tutorial, so any
references to sources of help are also appreciated. Thanks in advance for
your help!


The last part is relatively easy.

It says match anything that is either
NOT a digit [^\d]
or
is the end of line.

I think equivalent expressions would be:

(\D|$)

([\D$])

My guess is that the last would be the most efficient.

The first expression is more complex.

(?:pattern) is a non-capturing match.

In this case you are looking to match, but not capture, any single
character
within the opening and closing brackets. The opening bracket is just
after the
initial colon ":", and the closing bracket is just before the ending close
parenthesis.

The carat (^) and right bracket (]) are preceded by the forward slash (\)
so
they will be interpreted as literals within the bracket expression. All
of the
other characters within the bracket expression should be interpreted as
literals, if I recall correctly.


--ron