Regular Expressions 101

Community Patterns

1

ตรวจสอบพยัญชนะต้นตัวสะกดสระและวรรณยุกต์ไทย

Created·2026-01-22 01:36
Updated·2026-01-23 12:42
Flavor·JavaScript
ตรวจสอบพยัญชนะต้น (ต้องมี) ตรวจตัวสะกดสำหรับสระที่ต้องมี ตรวจสอบการวางสระและวรรณยุกต์ไทย หมายเหตุ การตรวจสอบตัวสะกดในภาษาไทยตรวจสอบได้ยากเพราะภาษาไทยเป็นภาษาที่เขียนติด ๆ กันไม่มีการแบ่งคำอย่างชัดเจนทำให้การอ่านภาษาไทยผู้อ่านต้องใช้ความหมายของคำในการตัดสินการอ่านแบ่งคำตามความเหมาะสมเช่นคำว่า "ตากลม" อาจอ่านเป็น "ตาก-ลม" ก็ได้ หรืออ่านเป็น "ตา-กลม"ก็ได้ ดังนั้นการเขียน Regex เพื่อทำการตรวจสอบอาจช่วยได้ระดับหนึ่ง อ่าจมีผิดบ้างถูกบ้าง แต่ก็ถือว่าเป็นเครื่องมือที่ใช้ช่วยเหลือในการตรวจสอบเพิ่มเติมได้ 80% ของความเป็นไปใด้ก็แล้วกันนะครับ หวังว่าการเขียนเพิ่มเติมส่วนนี้ จะมีประโยชน์บ้างไม่มากก็น้อย
Submitted by อธิปัตย์ ล้อวงศ์งาม

Community Library Entry

1

Regular Expression
Created·2023-07-09 07:25
Flavor·PCRE2 (PHP)

/
^(([5,6,7,8,9]{1})([0-9]{1})([0,1,2,3,5,6,7,8]{1})([0-9]{6})([v|V|x|X]))|(([1,2]{1})([0,9]{1})([0-9]{2})([0,1,2,3,5,6,7,8]{1})([0-9]{7}))
/
gm
Open regex in editor

Description

Extract the Data from Sri Lankan National Identity Card

The SL NIC could be divided into two groups,

  1. Before 2016 (9 alphanumeric digits with one English letter)
  2. After 2016 (12 alphanumeric digits)

NICs issued before 1 January 2016, each NIC has a unique 9-digit number and a letter, in the format 000000000V (where 0 is a digit and V is a letter). The first two digits of the number are the holder's year of birth (e.g.: 91xxxxxxxx for someone born in 1991). The next three digits contain the number of the day in the year for the person's birth. For females, 500 is added to the number of days. The next three digits number is the serial number of the issued day. The next digit is the check digit. The final letter is generally a 'V' which indicates that the holder is eligible to vote in the area. In some cases the final letter can be 'X' which usually indicates the holder is not eligible to vote; possibly because they were not permanent residents of Sri Lanka when applying for a NIC. (Directly copied from Wikipedia)

  1. Old NIC - Before 2016

Birth Year: 72 Day Count for Birthday: 244 Serial Number; 152 Check Digit: 4 Special Letter: V

The NIC Number: 722441524V

  1. New NIC - After 2016

Birth Year: 2001 Day Count for Birthday: 253 Serial Number; 0297 Check Digit: 6 Special Letter: -

The NIC Number: 200125302976

  • Can be used for any men or women born in 1950-2999
Submitted by Aadhil Ahamed (Find me on GitHub: https://github.com/AadhilMR)