# Литералы регулярных выражений(regexp)

Регулярные выражения - это мощное средство поиска по шаблону в строках. Vala имеет экспериментальную поддержку литералов для регулярных выражений. Например:

```csharp
string email = "tux@kernel.org";
if (/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.match(email)) {
    stdout.printf("Valid email address\n");
}
```

i в конце делает выражение не чувствительным к регистру. Вы можете хранить регулярное выражение в переменной типа Regex:

```csharp
Regex regex = /foo/;
```

A example of regular expression replacement:

```csharp
var r = /(foo|bar|cow)/;
var o = r.replace ("this foo is great", -1, 0, "thing");
print ("%s\n", o);
```

The following trailing characters can be used:

* *i*, letters in the pattern match both upper- and lowercase letters
* *m*, the "start of line" and "end of line" constructs match immediately following or immediately before any newline in the string, respectively, as well as at the very start and end.
* *s*, a dot metacharater *.* in the pattern matches all characters, including newlines. Without it, newlines are excluded.
* *x*, whitespace data characters in the pattern are totally ignored except when escaped or inside a character class.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vala.gitbook.io/vala/experimental-features/regexp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
