An open API service indexing awesome lists of open source software.

https://github.com/banjo/regcode

🔷 Create regular expressions easily with code
https://github.com/banjo/regcode

regcode regex regular-expression regular-expressions

Last synced: 5 months ago
JSON representation

🔷 Create regular expressions easily with code

Awesome Lists containing this project

README

          




Regcode logo

Create regular expressions easily with code



npm


Docs •
Demo •
Features •
Examples •
API •
License

---

![screenshot](https://raw.githubusercontent.com/banjo/regcode/main/docs/static/regcode-light.svg)

## :heavy_check_mark: Features

* Create Regular Expressions with code
* English-like syntax that is easy to read
* Easy to learn, easy to read
* Simple API
* Convert to Regex or match directly to a string
* Get started in minutes
* No need to learn Regex to create an expression

## :clipboard: Examples

These are some basic examples, there are many more examples over at our [docs](https://regcode-docs.netlify.app) page. You can also try it interactively [here](https://www.regcode.netlify.app).

```ts
// use values
const code = "[character]"
const regex = "/[A-Za-z\u00C0-\u017F]/"

// use logic
const code = "[character]{oneOrMore}[or][number]"
const regex = "/(?:[A-Za-z\u00C0-\u017F]+|\d)/"

// use methods
const code = "normal(H[or]hello) [whitespace] [character]{oneOrMore}"
const regex = "/(?:H|h)ello\s[A-Za-z\u00C0-\u017F]+/"
```

## :cloud: API Example

Install Regcode with NPM or Yarn.

```bash
# npm
npm install regcode --save

# yarn
yarn add regcode

```

Simply create the class and begin using it.

```ts
import { RegCode } from "regcode";

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"]
```

## License

MIT