-1

Any one can show me how to get VARIABLE02 from the string below convert(nvarchar(10),convert(datetime,VARIABLE02 , 121), 103)

convert.*(.+,(.+),.+)

The above regex is working with convert(datetime,VARIABLE02 , 121), but once in multiple instances, it would stuff up.

Thanks for advice

Bin

yangbin990
  • 83
  • 7

3 Answers3

0

You could try using a negative lookahead to assert what follows after the second comma is not convert and capture your value in the first capturing group using a negated character class ([^,]+):

convert\([^,]+,(?!convert)([^,]+)

That would match

  • convert Match literally
  • \( Match opening parenthesis
  • [^,]+, Match not a comma one or more times using a negated character class, then match a comma
  • (?!convert) - Negative lookahead which assert that what follows is not convert
  • ([^,]+) Capture in a group matching not a comma one or more times (This will contain your value)
The fourth bird
  • 154,723
  • 16
  • 55
  • 70
0

You could try:

(?<=,)[a-zA-Z0-9]+(?= ?,)

builder-7000
  • 7,131
  • 3
  • 19
  • 43
0

Seems not possible by using regex itself.

The slide below give a good explanation: Can regular expressions be used to match nested patterns? Can regular expressions be used to match nested patterns?

But thanks all.

yangbin990
  • 83
  • 7