2) ] Since character 2) from the list above is used to close a character class, some regular expression flavours will let you get away with not escaping a ']' as long as it's outside a character class.1) [ Character 1) from the list above obviously needs to be escaped outside a character class, otherwise, you'd never be able to define a character class!.1) [ Purpose: Start of character class.Ĭharacter Escaping Outside A Character Classīut what can we say about characters that always need to be escaped outside a character class? For starters, let's consider the 5 characters from the list above, and take note of a few differences:. In the sections Character Classes in Regular Expressions - A Gentle Introduction and Character Ranges & Class Negation in Regular Expressions we reviewed the 5 characters that need to be escaped inside a character class (anywhere inside ): Character Escaping Inside A Character Class To keep this simple, this article will not consider Unicode characters and instead focus only on single-byte ASCII characters. When learning how to correctly escape characters in a regular expression, it helps to divide the escaping rules into two different lists of characters that need to be escaped: One for characters inside a character class, and one for characters outside a character class. In this section, we'll try to gain a fairly comprehensive understanding of the most common ways to escape characters in a regular expression. There's just one remaining major common cause of confusion: character escaping. You'll be pleased to know that you're now very close to being able to read or write almost any regular expression. In the last few sections of this series, we've gained an understanding of character classes, quantifiers and alternation. This article is part of a Series On Regular Expressions. Regular Expression Character Escaping - By Robert Elder
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |