Regex: How to find a "<" less than Symbol

  • Thread starter Thread starter chemicalcold0
  • Start date Start date
C

chemicalcold0

Hi there,

since < has a meaning in c# for regular expressions and \< says it's
an unrecognized escape sequence, I'm pretty lost parsing html tags
without replacing them first with another character or string.
Does anyone have a hint for me on how to get c# Regex class to find
"<"?

Thanks in advance,

Prattel
 
since < has a meaning in c# for regular expressions and \< says it's
an unrecognized escape sequence, I'm pretty lost parsing html tags
without replacing them first with another character or string.
Does anyone have a hint for me on how to get c# Regex class to find
"<"?

You need to differentiate between the escaping that C# is involved in,
and escaping that regular expressions need.

The two simplest ways of expressing the string consisting of a
backslash and an open angle bracket are:

"\\<"

This uses \\ to form a single backslash in the string, using normal C#
escaping. The single backslash is used to escape the angle bracket from
the point of view of the regex.


@"\<"

This uses a C# verbatim string literal to represent the same string -
again, so the single backslash is used to escape the angle bracket.
 
Hi there,

since < has a meaning in c# for regular expressions and \< says it's
an unrecognized escape sequence, I'm pretty lost parsing html tags
without replacing them first with another character or string.
Does anyone have a hint for me on how to get c# Regex class to find
"<"?

Thanks in advance,

Prattel

"\\<"

or:

@"\<"
 
Back
Top