RegEx (sigh, yes again)

I would like to be able to create a function where I can pass in a STRING containing an SQL Query and return an ARRAY of all the words in the STRING. “Words” would be defined as any valid SQL keyword or valid SQL symbol, excluding numbers that are not part of the symbol, as well as all braces, brackets, and other characters (period, comma, semi-colon etc)

SELECT * FROM myTable WHERE x93=14/z

would return
“SELECT”,“FROM”,“myTABLE”,“WHERE”,“x93”,“z”

I’m sure there is a RegEx way to do this quickly…

oh and toss out quoted strings as well :slight_smile:

Or if it would be easier… a modified version of Instr that followed the same rules as above

x=SuperInstr(SQL,"FRO") would be zero
x=SuperInstr(SQL,"FROM") would be 12

assuming SQL was the sample from above.
basically it needs to look for whole words that are valid

Try this:

"[^"]*(?:"|\\z)(*SKIP)(*FAIL)|'[^']*(?:'|\\z)(*SKIP)(*FAIL)|\\b[a-z]\\w*\\b

I’ll try that thanks…

What I love about RegEx?
Its easy to read, easy to understand structure… oh wait did I really say that? :smiley:

EDIT : Kem… shouldn’t there be some numbers in there someplace?

1234 is not acceptable, but ABC123 is

The part of the pattern that will actually match words looks for a letter as the first character.

See… that is why you a the “RegEx King” and I am but a pawn in a sea of pawns :smiley:

Has anyone ever made a RegEx compiler (transpiler?) ?

Bit like SQL or something. Ok maybe not SQL, but you get what I mean.

My head just refuses to understand regex, no matter how I bribe or threaten it.

EDIT : found this - https://simple-regex.com/

Here, Here!
I have no problem reverse engineering almost anything, I have no problem with mathematics, or almost any programming problem I have ever set my mind to. But RegEx? it just refuses to light that bulb for me.

Write a regular expression editor. It’s simple after that. :slight_smile:

(Don’t really do that.)

[quote=335878:@Kem Tekinay]Write a regular expression editor. It’s simple after that. :slight_smile:

(Don’t really do that.)[/quote]
Kem… that really isn’t as silly an idea as it sounds…
I have learned a lot about interpeters and compilers by actually attempting (with limited success) to write them

I didn’t mean for that to sound silly. If I’m considered an “expert”, it’s only after I wrote RegExRX.

RegExRX - A MUST have for Xojo Devs. Because i generates Xojo Code! :wink: