Kevin DiTraglia
Kevin DiTraglia

Reputation: 26078

Simple RegEx Expression

OK I am admittedly terrible at RegEx as I rarely have a need for it, but I found myself in a situation where a simple parse just was not cutting it. So after attempting to teach myself the entirety of RegEx while sitting here at work I finally give up and asked the experts. I am simply parsing a sql file and splitting it on the GO statements. Problem is I can't pull GO out of other words, like CREATE TABLE GOPHER. So I think I'm pretty safe by saying I split when I have a line that's is only spaces and the word GO case insensitive.

Here's what I have, I think it's pretty close, but I am doing something wrong as it's not matching anything at the moment.

^+\s*[GO]\s*\Z

*note case can be taken care of with the ignore case flag, so I'm not to worried about that

If I simply write

^+[GO]+\Z

It mostly works, but it doesn't ignore the spaces before and after the GO, I thought \s* would do it, but it seems to be returning no matches. Anybody can fix this for me, with a short explanation of what I'm flubbing up here?

Upvotes: 0

Views: 120

Answers (1)

Joshua Honig
Joshua Honig

Reputation: 13215

Use Regex.Split with the pattern @"(?<=\bGO\b)", which matches the zero-width boundary immediately after the complete word "GO".

See

Upvotes: 3

Related Questions