If I understand you correctly, you want to find all occurrences of the '#'
character that are enclosed in a string that is enclosed in single quotes,
within a string. In your examples, there was only ONE occurrence of the
'#' character within any substring, so I wrote the following with that
rule in mind:
(?<='[^'#]*)#(?=[^'#]*')
This is a regular expression that begins with a positive look-behind and
ends with a positive look-ahead. The effect of these is that the match
will be matched, but the '#' character is the only one that is captured.
The first positive look-behind asserts that the '#' character must be
preceded by a single quote character followed by zero or more characters
that are not single quotes or '#' characters. The positive look-ahead
indicates that the '#' character must be followed by zero or more
characters that are not a single quote or a '#' character, followed by a
single quote.
In your example (below), there will be 3 matches, one per '#' character:
value = 'hello this is#the example' OR
value2 <= 'this#one' AND value3
IS NOT 'something#'
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
Networking Components, Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
Hello Peter!
thanks for your reply, probably I have not written the things
properly. Sorry for my english.
ok lemme try again to re-phrase my need,
I have a string for example: (see it as string not as operation
keywords like OR etc, they are just part of the string - it is some
special sql string to modify)
value = 'hello this is#the example' OR value2 <= 'this#one' AND value3
IS NOT 'something#'
within this string you see the character "#" without the quotas
several times. I want to replace any occuring "#" (without quotas)
with character " " (without quotas) (blank character)
the rule for this is the string:
will start with any number of characters or numbers: e.g. value
then it will be followed by: blank [any number of characters] blank
e.g. [blank]IS NOT[blank]
then: character '
then: <the text which shall be searched for # and replaced by a blank>
then character '
this would represent the search criterion, this part shall be searched
as often it occurs inside this string and then apply the replacement
(the example text is just symbolic to show you what I want to achieve,
don't try to interprete the operators or the sense of the string)
hope it's now a little clearer,
thanks in advance
Hans