[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [Type](https://evolu.dev/docs/api-reference/common/Type) › regex

```ts
function regex<Name>(
  name: ValidateConcreteTypeName<Name>,
  pattern: RegExp,
): BrandFactory<Name, string, RegexError<Name>>;
```

Defined in: [packages/common/src/Type.ts:5632](https://github.com/evoluhq/evolu/blob/f0109fb501a593010e858e39248dde1200eeb2d7/packages/common/src/Type.ts#L5632)

String [Brand](https://evolu.dev/docs/api-reference/common/Brand/interfaces/Brand) constrained by a regular expression.

### Example

A non-empty string using the URL-safe alphabet:

```ts
import {
  assertEqual,
  assertErr,
  assertOk,
  assertType,
  Data,
  String,
  regex,
  type Brand,
} from "@evolu/common";

const UrlSafeString = regex("UrlSafeString", /^[A-Za-z0-9_-]+$/u)(String);
type UrlSafeString = typeof UrlSafeString.Output;

assertType<string & Brand<"UrlSafeString">, UrlSafeString>();

assertOk(UrlSafeString.fromUnknown("abc-123_DEF"), "abc-123_DEF");
const invalid = UrlSafeString.fromUnknown("not safe");
assertErr(invalid);
assertType(Data, invalid.error);
assertEqual(invalid.error, {
  type: "UrlSafeString",
  value: "not safe",
  source: "^[A-Za-z0-9_-]+$",
  flags: "u",
});
```