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

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
 
J

Jon Skeet [C# MVP]

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.
 
L

Lasse Vågsæther Karlsen

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:

@"\<"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top