I have a block of text from which I need to extract & replace certain occurrences of text. The pattern I'm looking for has 5 components in this sequence:
1) /*<<@*/
2) any characters & symbols except this symbol combo: /*
3) /*
4) any upper or lower case letter, number, space or underscore
5) */
For example, I am so far unable to devise a regex pattern that can extract the 3 occurrences of the pattern from this text:
DECLARE @myDate DATETIME = /*<<@*/ '2018-07-20 00:00:00' /*My Date>>*/
DECLARE @myString VARCHAR(MAX) = /*<<@*/ 'whatever?' /*My String>>*/ DECLARE @isTrue VARCHAR(MAX) = /*<<@*/ 1 /*My Bool>>*/
These are the 3 occurrences that should be found:
1) /*<<@*/ '2018-07-20 00:00:00' /*My Date>>*/
2) /*<<@*/ 'whatever?' /*My String>>*/
3) /*<<@*/ 1 /*My Bool>>*/
But I always get 2 occurrences -- the second line is considered a single match instead of 2 matches:
1) /*<<@*/ '2018-07-20 00:00:00' /*My Date>>*/
2) /*<<@*/ 'whatever?' /*My String>>*/ DECLARE @isTrue VARCHAR(MAX) = /*<<@*/ 1 /*My Bool>>*/
Here is an example regex pattern, one of many that I've tried:
(\/\*<<@\*\/){1}(.*){1}([a-z]|[A-Z]|[0-9]|_|\s)*(>>\*\/){1}
If I move the 3rd DECLARE onto its own line, it works (because the . symbol stops at line returns), but I need to be able to extract the occurrences separately when they are on the same line.
I've tested all my patterns against the text using regexr.com and regexstorm.net. My patterns break down on the second component: I can find no way to include in the pattern any characters or symbols except /*
, the regex always grabs too much. I've tried negative lookaheads for /*
. I've tried explicitly specifying all valid characters but I couldn't find a way to NOT match the /*
combo.
Any help will be appreciated!