# Regex in Visual Studio Code

VSCode primary support for regular expressions. Find and replace menu dialog can be opened with `Ctrl + F` key combination.

![find and replace menu options](https://cdn-images-1.medium.com/max/1000/1*MKGNjNZcN6OpG3aH8JsAig.png)

It support plain text small, capital letters and regex.

#### New line (\n), spaces and tabs

We can search for new lines, carriage return, tabs, and spaces. Here for example, we would like to replace new line with comma (,) so that all the entries will be in csv.

![](https://cdn-images-1.medium.com/max/1000/1*zaFnO5wnTRz-cJNjNd1NRw.png)

The final result would look like this

![conversion from newline to csv](https://cdn-images-1.medium.com/max/1000/1*hqatogd3RAHuGReoplXgrQ.png)

***

#### Character set match

With help of square brackets \[ ], you can match for **one** (only one) of a set of characters.

![](https://cdn-images-1.medium.com/max/1000/1*9yMtD3-ecdEYfnqPxZ74PQ.png)

Here the search goes for either of 1, 2, or 3 after immediately after # symbol.

More examples,

* Important\[:!,] searches for `Important:` , `Important!` or `Important,`.
* \[AEIOUaeiou] searches for one of the letters in this set.

> Important ✨

> 9 is a character, and 99 is a number with two characters 9 and 9.

**Character ranges**

For example for a long range of numbers or alphabets, it would be cumbersome. You can represent a range with a `—` which acts as a metacharacter inside the square brackets `[]` and outside it acts as a literal character.

* Number `[0-9]` — matches number `0` to `9`.
* Alphabets `[A-Z]` — matches `A` to `Z`.
* Small letter `[a-z]` — matches `a` to `z`.

**Exclude character**

Search for words without the listed characters in the set. Here, `^` is the metacharacter for negation.

* `[^aeiou]` matches consonants
* `[^05]` matches the numbers not divisible by 5.
* `[^a-zA-Z]` matches other than alphabets.

For example,

* `medi[^a]` matches medium

![check word with out a specific literal](https://cdn-images-1.medium.com/max/1000/1*ki1OF5uV7BJc4UksF5WOyQ.png)

> **Note** 📝\
> \
> `] - ^ \` are not literals inside the `[ ]`. But, `. * ! , ; & $` are all the literals. This means,\
> \- `a[sk.]txt` matches `a.txt`, `astxt`, `aktxt` only.\
> \- we can escape `—` inside the brackets, as `file[0\-]` which also matches `—` literal.


---

# 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://i.janardhanpulivarthi.com/season-2/regex-in-visual-studio-code.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.
