-1

I need to write Regex for highlighting open paranthesis "{" given only when it is given in 3rd index of given string input for C# language.

For Example

hi{there

In below example, i have added { at 3rd position, so it "{" needs to be highlighted

As i am new to Regular Expression, i dont know how to give condition for this.

Kannan
  • 191
  • 1
  • 1
  • 10
  • 2
    You know what you want but have you tried anything in order to achieve it before posting a question? – Gilad Green Apr 24 '17 at 04:52
  • 2
    1. SO is not a coding service where you deliver specs and we do your work for you. Try it yourself first, lookup how to use regular expressions in c# and try to format your own expression. 2. Its not clear at all what `3 character index` is. `{ must be highlighted ` - Its not clear at all what you want with this either and the solution depends on the platform and how the text is being displayed. – Igor Apr 24 '17 at 04:55
  • yes i tried. But could not find any examples for matching character based on its index. So i am stucked here. – Kannan Apr 24 '17 at 04:56
  • yes, i have updated the requirement. – Kannan Apr 24 '17 at 05:01

1 Answers1

1

If you need your pattern to match only if it comes at the N-th position, you may use positive lookbehind ((?<=...)) checking "start of string (^) followed by N-1 characters (.{N-1})" condition. In your particular case it's

(?<=^.{2})\{

See demo

Dmitry Egorov
  • 9,542
  • 3
  • 22
  • 40