VBA Like operator in C

L

Lars Schouw

Did anyone setup the regular expressions needed to replicate the VBA
Like operator in C?

Lars
 
D

Dann Corbit

Did anyone setup the regular expressions needed to replicate the VBA
Like operator in C?

Get the PostgreSQL code and examine their LIKE operator. It is written
in C and is Berkeley licensed.

As an alternative, do a web search for any of the plethora of regexp
tools available.
 
L

Lars Schouw

Thank you.
I have a regex parser, my problem is to find out if someone knows all
the correct syntax of regular expressions to search for if I want to
match the VBA Like statement.

PostgreSQL Like sumular to VBA? I looked and it does not look like it
to me.

Lars
 
L

Lars Schouw

Open Office used to have a mapping between Like and regexp. I am not
sure why they took the code out and if it works?

String VBALikeToRegexp(const String &rIn)
+ {
+ String sResult;
+ const sal_Unicode *start = rIn.GetBuffer();
+ const sal_Unicode *end = start + rIn.Len();
+
+ int seenright = 0;
+
+ while (start < end)
+ {
+ switch (*start)
+ {
+ case '?':
+ sResult.Append('.');
+ start++;
+ break;
+ case '*':
+ sResult.Append(String(RTL_CONSTASCII_USTRINGPARAM(".*")));
+ start++;
+ break;
+ case '#':
+ sResult.Append(String(RTL_CONSTASCII_USTRINGPARAM("[0-9]")));
+ start++;
+ break;
+ case ']':
+ sResult.Append('\\');
+ sResult.Append(*start++);
+ break;
+ case '[':
+ sResult.Append(*start++);
+ seenright = 0;
+ while (start < end && !seenright)
+ {
+ switch (*start)
+ {
+ case '[':
+ case '?':
+ case '*':
+ sResult.Append('\\');
+ sResult.Append(*start);
+ break;
+ case ']':
+ sResult.Append(*start);
+ seenright = 1;
+ break;
+ default:
+ if (NeedEsc(*start))
+ sResult.Append('\\');
+ sResult.Append(*start);
+ break;
+ }
+ start++;
+ }
+ break;
+ default:
+ if (NeedEsc(*start))
+ sResult.Append('\\');
+ sResult.Append(*start++);
+ }
+ }
+
+ return sResult;
+ }
+
 
S

spinoza1111

Did anyone setup the regular expressions needed to replicate the VBA
Like operator in C?

Lars

Like is a half-hearted implementation of regular expressions, so:

* Learn regular expressions, or
* Call VBA from C for your Like expressions
 
L

Lars Schouw

I know regular expressions.. sort of..

But I am not sure which once functionality I want to replicate in VBA
since I am not sure what it can do.
I guess I could concentrate on a subset for now.

So if someone have already done the mapping (the work) that would be
great.. guess I am not that lucky.

Lars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top