How to search with Regular expressions in the QuranThere is an elegant way for searching in the Holy Quran text by using a simple language called: Regular Expression


Written by: Ayman Teryaki
Date: 2023-01-07 20:22:34

Subject related to: regexp

Introducing Regular Expressions

Regular Expressions (abbreviation: RegEx) are signs which built in an intelligent and easy to understand system. We have the ability to use this system in and improve our work much faster and even exactly. If users of OpenQuran doing research to the counts and calculations of Letters/words/verses and there gematrical values than its very important to understand the idea behind RegEx. RegEx is mostly used in programming languages, databases, search engines, Spam filters etc. It's easy to understand but needs from us more the artistic talent on how to build the RegEx definitions. There are also a lot of Sites which have more detailed informations on how to use this small powerful language, but the would like easily show how to use with the Arabic language and specially for the Quran.

The theoretical part

RegEx Meaning
. a dot replaces any sign like letter, number oder space
* a star after a sign means: this sign can exist even many times or it does not exist at all
.* The example finds this whole string
[a-z]* finding only small letters or none
(?i) finding small or capital letters
th.*s find th………….s
^A The text must begin with  A
s$ The text has to end with s
[a-z|A-Z] Only small or capitel letters
[^a-z] find none of these letters
[a1] find a or 1
[^abcd] find none of a b c or d
s|t The OR operator: finds s or t
M(e|i)*r (e or i) find: Mr, Mer, Meir, Mier or Mir
M(e|i)?r (e or  i) 1 same as befor but also find Miiiiieeeeer
a+ finds at least 1 a or many aaaaaaa…..
a{5} finds 5 times aaaaa
a{3,} a must be 3 times or more
a{,3} a exits 3 times or lesser
a{3,8} a must exist 3 to 8 times
w finds letter chars
\W finds no letter chars
\d finds only numbers [0-9]
\D finds no numbers
\s finds white space
\S finds no white space
\b sign/s limit \bword\b
\B sign/s ar not limited
\t tab
| or
[ ] contains many differt signs
( ) contains a group of sign/string
^(?=.*x) The "AND" Operator is only offered in few programming languages such as PHP.
Example: ^(?=.*a)(?=.*b)(?=.*c).*
This means that a, b and c are a MUST BE in a word/phrase. It will show clickbar, baraca but not in car

The practical part (Using in AlQuran)

choose the table quran which is automatically selected. Notic that the most confusing part in our work is by combinig arabic chars with latin signs. That´s why we´re forced to change the direction of the write method in some examples to be "RightToLeft" (RTL).
  • The orange colored expressions can be used in the search input (Click on the example to send to search).
  • The gray colored sentences are the result of our search
  • We can also check "analyze" instead of the normal searching. It shows detailed informations about the calculation.


This will count any letter found in the whole quran. (run Analyze "right click" instead of normal search. Cause OQ colorizes every sign to red)
326030 Entries (328158 with Basmalah/s* ), 6234 Verses in 114* Suras
views verses which begin with a 7 letters word like ( واقيموا الصلوه ) in verse 2:43 //
304* Entries, 304* Verses in 77 Suras
views any word which consists of 6 letters
11163 Entries (11387 with Basmalah/s ), 4669 Verses in 112 Suras
^[\w| ]{19}ا
searches for Alif letter after counting 19 leters or spaces
710 Entries, 710 Verses in 95* Surahs
^(\w[ ]*){114}ا
searches for Alif letter after counting 114 letters (WITHOUT counting spaces) //
57* Entries, 57* Verses in 23 Suras


find verses which begin with الرحمن
3 Entries, 3 Verses in 3 Suras. Count Sura Numbers: 76*


find verses which end with الرحيم
33 Entries, 33 Verses in 19* Suras, count dura numbers 551*,  Letters count of all found verses 1444*


find all double لل
3253 Entries (3365 with Basmalah/s ), 2147* Verses in 96 Suras


find the letter B or S or M etc (letters of Basmalah)
221654* Entries (19*19*614) (223782* with Basmalah/s* ), 6234 Verses in 114* Suras, Count Sura Numbers: 6555*


find any letter accept B or G or D etc.. (None initial letters)
315155 Entries (317507 with Basmalah/s ), 6234 Verses in 114* Suras
Searching for some unique words like Allh = الله
it´s important to have some knowledge about the different forms of this words. Some times its written LLH = لله or FALLH = فالله or BALLH = بالله or WLLH = ولله  but not DLLH = ضلله .
The best definition we found to get all words is as follow:

( |ا|و|ف|^)لله( |$)

2698* Entries (2810 with Basmalah/s ), 1820 Verses in 85 Suras
finds the word ALQRAAN exactly the way its written
43 Entries, 43 Verses in 28 Suras, Count Sura Numbers: 893*
finds the word KTB or KTAB exactly the way they are written
102 Entries, 95* Verses in 45 Suras

(\b(ال|و|ف|ء|ب)*ا[ء]*له(ا|ك|كم|نا|ه|ين|ت|تهم|تي)*\b)|( |ا|و|ف|^)لله( |$)|اللهم

This one is a difficult example showing the roots of ALH اله in all different shapes used in the Quran
2849 Entries, 1878 Verses in 86 Suras


Here we need the word ABDA ابدا but without the letter ع before
28 Entries, 28 Verses in 15 Suras

ن[ ]*و[ ]*ن

This will find يمنون in one word or in 2 words beside each other بالسنين ونقص
247* Entries, 235 Verses in 65 Suras
To look for every verse which begins with a specific letter and ends with another specific letter we do as follow:
We search for verses that begin with Ba ب and ends with Mim م like the Basmalah (first verse in surah 1):


AlQuran finds 3 verses in such manner which consists of 114 (19*6) letters.
If we also search for verses that begin with Saad ص and end with Nun ن (last verse of surah 1)
we´ll find also 3 verses that have a gematrical value of 9728 (19*512):


We can also include both mehtods in one definition!
For example we search for verses which begin with letter Be ب or Saad ص and end with Mim م or Nun ن :


In such manner we find 46 verses which have the gematrical value of 130473 (19*6867)
If we want to look for all words which begin with a specific letter (e.g. the letter س ) \bس+
Some times letters have 2 or more different shapes like Alif and Hamza.
The following example will find all words begining with Alif or Hamza: \b[ا|ء]+
At the begining of the verse, there must be (a word with 3 letters) than (Space) than (ALLH). same as بسم الله

^\w{3} الله

Now we need verses that must have letter ص and كت and ال same as in this verse:
واكتب لنا فى هذه الدنيا حسنة وفى الءاخرة إنا هدنا إليك قال عذابى أصيب به من أشاء ورحمتى وسعت كل شىء فسأكتبها للذين يتقون ويؤتون الزكوة والذين هم بءايتنا يؤمنون


If you wanna get the reversed results of the example before, which means we get verses that DO NOT have letter ص and كت and ال same as in this verse:
إياك نعبد وإياك نستعين
You need to change the equal mark (=) to exclamation mark (!)


References to Regular Expressions

If you have any question regarding RegEx in Alquran than we are glad to help.

Privacy Overview This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience. Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.

Please Note: We use COOKIES to save your session with your chosen options to make you feel comfortable while exploring the web site
Cookie Overview Accept & Settings

init uninit الم الر المر المص كهيعص حم طه طسم طس يس ص حم عسق ق نون