3

I am trying to write a regex for AvalonEdit.TextEditor to mark everything after the second | a certain color.

Example(value should be a color):

action|key|value

I am trying something like this but it doesn't work because I can't specify the group I wanna color.

^[^\|]*\|[^\|]*\|(?P<value>[^\|]*)

Any ideas?

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
Alioooop
  • 465
  • 5
  • 12

1 Answers1

3

Try this: (?<=[^\|]+\|[^\|]+\|)(?<value>[^\|]+)

The positive look-behind (?<=) will make sure action and key are not part of the match.

Normally you shouldn't use non-fixed length look-behinds but maybe this works for you.

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
  • 1
    This rule gives me a exception: A highlighting rule matched 0 characters, which would cause an endless loop. Change the highlighting definition so that the rule matches at least one character. Also tried it here https://regex101.com/ with a different error: A quantifier inside a lookbehind makes it non-fixed width – Alioooop Feb 16 '17 at 12:29
  • 1
    regex101 doesn't have C# RegEx. Try [Regex Storm](http://regexstorm.net/tester). Too bad this doesn't work with Avalon's textEditor. Can you provide a [mcve]? I replaced the `*` with `+` maybe that already does the trick. – Manfred Radlwimmer Feb 16 '17 at 12:31