---
url: /reference/Function.wordRegex.md
---
# Function: wordRegex()

* **Exported from**: `rolldown/filter`
* **Type**: (`str`: `string`, `flags?`: `string`) => `RegExp`

Constructs a RegExp that matches the specified string with word boundaries.

This is useful for plugin hook filters when you want to match a complete word-like token,
such as matching `node_modules` but not `node_modulesa`.

## Parameters

### str

`string`

the string to match.

### flags?

`string`

flags for the RegExp.

## Returns

`RegExp`

## Example

```ts
import { wordRegex } from '@rolldown/pluginutils';
const plugin = {
  name: 'plugin',
  resolveId: {
    filter: { id: wordRegex('node_modules') },
    handler(id) {} // called for IDs containing `node_modules` as a standalone token
  }
}
```
