Introducing Regcode - Create Regular Expressions Easily with Code
Tags: regex, tool, webdev, programming
Published: 2021-05-31 08:44:27

Every programmer has most likely heard the term Regex, or Regular Expressions. It's extremely useful, but the unreadable syntax makes it hard the learn and easy to forget once you've learned it. 

I really wanted to make Regex easy, so therefore I created [**Regcode**](https://www.regcodejs.com) - a tool to create regular expressions easily with code ([Github repo](https://github.com/banjo/regcode) for those interested, it's open-source).

Regcode can be easily summarized in this picture:

![regcode explanation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c458l4sbpfyw0i0nmsqi.png)

---

## Features

Regcode comes loaded with different features to make it easier for the developer to create their own regular expressions - without actually knowing Regex.

- Create Regular Expressions with simple code
- English-like syntax that is easy to read
- Easy to learn, easy to read
- Simple API
- Easy documentation
- Convert to Regex or match directly to a string in the API
- Web app to use it create it in the browser
- Get started in minutes
- No need to learn Regex to create an expression
- Free and open-source

---

## Regcode - the simple way to write Regex

As you can see on the picture above - Regcode is not at all difficult to use. The syntax is basically English, making it easy to read and learn.

```txt
<matchAll> hasBefore(https://) [character]{any} normal(.) [character]{any} hasAfter(.[character]{2,6});
```

This is a simple regcode to match different URLs that ends with `.com` or `.net` (and starts with `https://` but does not include it). The syntax makes it easy for the developer to write, but also for other developers to read and actually understand. The regex it generates is much harder to understand.

```txt
/(?<=https:\/\/)[A-Za-z\u00C0-\u017F]*\.[A-Za-z\u00C0-\u017F]*[A-Za-z\u00C0-\u017F]{2,6}/g
```

---

## Web app - use it directly in the browser

![Web app](https://i.imgur.com/ogqxtWk.png)

You can create your own regcode directly in the browser over at the [main page for regcode](https://www.regcodejs.com).

Generate your regex directly, and compare your code directly with your own strings to see if they match.

---

## API - use it in your project

The API can be installed directly from [NPM](https://www.npmjs.com/package/regcode) and used inside of your JavaScript/TypeScript projects.

Install it as usual with NPM.

```vb
npm install regcode --save
```

After that, import it and use it.

```ts
const regCode = new RegCode();
const code = "hasBefore(https://) normal(www.) [character]{any} normal(.com)[or]normal(.net)";
const sentenceToMatch = "The url is https://www.regcodejs.com, here you go!";

// look for matches
const match = regCode.match(code, sentenceToMatch);    // ["www.regcodejs.com"]

// or convert to regex and match the normal way
const regex = regCode.convert(code);
const match = sentenceToMatch.match(regex);           // ["www.regcodejs.com"]
```

---

## Documentation with examples

![Documentation](https://i.imgur.com/Y19Oq6C.png)

The documentation is short and hopefully easy to understand, with a lot of different examples to easily get you going. It's really easy to [get started with the basics](https://docs.regcodejs.com/). And for those eager to get going directly, you can start at the [examples](https://docs.regcodejs.com/introduction/examples) page.

---

Thank you for very much for taking your time and reading this post. I really hope Regcode comes to good use for you. Feel free to ask me if you have any questions, or create your own issues/pull request if you want to contribute to the project.