Thursday, March 31, 2011

Re: Regular Expression Help

On 01/04/11 07:35, Alessandro Antonello wrote:
> Hi, all.
>
> I have a problem building a regular expression for fields in a SQL UPDATE
> statement. The SET clause has the format as follows:
>
> field1 = 'value of field1', field2 = 'field\' 2 value'
>
> I have built a regular expression that can split the name of fields from its
> values. But when a value has an escaped single-quote the regular expression
> fails. I know that it fails because I am using the expression [^'] in between
> the parenthesis. But how to fix this?
>
> This is the regular expression I am using:
>
> /(\w+)\s*=\s*(('[^']*'\s*,)|(\d+\s*,))\s*/i
>
> Could someone help me with that?
>
> Alessandro Antonello
>

I think you could use non-greedy matching i.e. .\{-} and end at (or
maybe just before) a single quote not preceded by a backslash (maybe end
the pattern with [^\\]' if there must be at least one character between
the quotes).

See
:help non-greedy
:help /[]


Best regards,
Tony.
--
Loose bits sink chips.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment