2

I'm making a little HTML editor and I would like to know, how to return string/array of chars, that are/is between 2 characters (like > and < or " and ")

Example:

<>Text inside > and <<> or "Text inside " and "".
BartoszKP
  • 34,786
  • 15
  • 102
  • 130
BigBang1112
  • 123
  • 1
  • 1
  • 8
  • 2
    Use [Html Agility Pack](http://htmlagilitypack.codeplex.com/) if you want to parse html instead of string-methods or regex. However, the sample you've posted is not valid html. – Tim Schmelter Sep 29 '14 at 14:54
  • possible duplicate of [How do I extract a string of text that lies between two (parenthesis) using .NET?](http://stackoverflow.com/questions/378415/how-do-i-extract-a-string-of-text-that-lies-between-two-parenthesis-using-net) – Teslo. Sep 29 '14 at 14:58
  • Finally useful to add a link to this answer: http://stackoverflow.com/a/1732454/870604 ! – ken2k Sep 29 '14 at 15:01
  • Damn sorry guys, I forgot add c# to header – BigBang1112 Sep 29 '14 at 15:04
  • @user3923447 Actually the title shouldn't contain `C#` as there already is a tag – ken2k Sep 29 '14 at 15:05
  • 1
    @Teslo You're maybe right. I need to look at regex, what actually does. – BigBang1112 Sep 29 '14 at 15:06
  • @ken2k but some guys like me forgot sometimes read the tags – BigBang1112 Sep 29 '14 at 15:07
  • @BigBang1112 The established policy on SO is not to put tags in the title, regardless of one's preferences. – BartoszKP Sep 29 '14 at 15:11

1 Answers1

1

Take a look at Regular Expressions - they're perfect for this purpose.

Quick tip to help you along - the following expression should give you a match if 'abc' sits between the > and < characters:

(?<=\>)abc(?=\<)
HalliHax
  • 816
  • 2
  • 11
  • 26
  • 1
    I don't know if I agree that RegEx is "perfect for this purpose". As explained in [this SO Question and Answer](http://stackoverflow.com/questions/6751105/why-its-not-possible-to-use-regex-to-parse-html-xml-a-formal-explanation-in-la), using RegEx to parse HTML is not really possible. – Icemanind Sep 29 '14 at 15:32
  • 1
    True, if the OP cares about validating the HTML then this is the wrong way to go, but I was thinking more along the lines of extracting the contents of already validated HTML - displaying hints for attribute values etc. Either way, validating HTML is a different kettle of fish - I wouldn't even bother trying to do it myself. – HalliHax Sep 29 '14 at 15:47