npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

persian-rex

v2.3.3

Published

A collection of useful Persian / Farsi regular expressions

Downloads

222

Readme

persianRex

A minimal library of useful Persian / Farsi regular expressions for browser and NodeJS environment

travis-ci

Places that you can use persianRex

Getting started

You can download the latest release form the release page or use your preferred package manager.

via npm

npm install persian-rex --save

via bower

bower install persian-rex --save

Once downloaded you can include the dist file like this:

 <scirpt src="bower_components/persian-rex/dist/persian-rex.js"></script>

Or if you are using node:

 var persianRex = require('persian-rex');

Detecting Persian Numbers

The number RegExp will match any string that only contains Persian numbers.

 if (persianRex.number.test('۱۲۳'))
  makeInputsRTL();

Detecting Persian Letters

The letter RegExp will match any string that only contains Persian letters.

 if (persianRex.letter.test('ابپ'))
  makeInputsRTL();

Detecting Persian Text

The text RegExp will match any string that only contains Persian letters, Persian numbers or Persian punctuations.

 if (persianRex.text.test('ابپ۱؟ )()۲۳'))
  doSomething();

Detecting RTL characters

From version 2 of this library, rtl RegExp is added to give you the ability to detect if tested string contains only rtl characters or not. rtl characters are Persian letters, Persian numbers and only the punctuations that are rtl (not [] or / that are also used in English). This is added so that you can be absolutely sure that you are dealing with a rtl text. Here is the example:

  if (persianRex.rtl.test('،'))
  doSomething();
    
  if (persianRex.rtl.test('!'))
    doSomething(); //this line will not be executed

Punctuations

Since version 1.3.0 punctuations are added to the library and they are combined with the text method to create a more natural detection of Persian text. It's rare that anybody wants to test a string against Persian punctuation but we decided to expose is for our users. Here is how to use it:

 if (persianRex.punctuation.test('!()[]،؟«»؛'))
  doSomething();

Using has prefix

You can prefix any of the above methods with has.

 if (persianRex.hasNumber.test('ابپ۱۲۳۴۵۶123abc'))
  doSomething();

The if condition is true, because the string has a persian number in it. You can use hasLetter and hasText as well.

Lower level usage

You can also get the ASCI code ranges for Persian numbers and Persian letters to make your custom RegExps.

  var customLettersRegular = new RegExp('^' + persianRex.lettersASCIRange);
  var customNumberRegular = new RegExp('^' + persianRex.numbersASCIRange);
  var customNumberRegular = new RegExp('^' + persianRex.rtlPunctuationsASCIRange);
  var customNumberRegular = new RegExp('^' + persianRex.ltrPunctuationsASCIRange);

Sponsors

Many of regular expressions in this project is extracted from larger projects such as Themeyab.com, If you think I'm are missing an important regular expression, feel free to open an issue on this repository and I will include it in the next version.