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-01-02 01:10
Flavor·.NET 7.0 (C#)

@"
(?=^.{1,80}$)(^[^\p{C}<>+=;,*?\\\/\[\]\:\|""]+$)
"
gs
Open regex in editor

Description

There are specific requirements for the different components of a UNC path. While it's possible to try and validate the entire UNC path in one go, you quite often end up needing to break the path down anyway unless simply handing it off to some other library (in which case they should be providing validation for you!) and it's a lot simpler to validate the components individually.

Unfortunately, there can be quite a lot of flexibility with UNC paths, and Microsoft's Type Definition only goes so far, as it says that the format can depend on the protocol.

Thier type definition says that a share name must be 1-80 characters long, and the allowed characters are (hexidecimal ASCII/Unicode/UTF-8) x20-21, x23-29, x2B-2E, x30-39, x40-5A, x5E-7B, and x7D-FF. Careful observers may note that this actually includes some non-printable characters, notably x7F, the Delete code. I haven't had a chance to test whether you can actually create a share that includes it though.

My use case is UNC for SMB/CIFS, so I checked the SMB/CIFS protocol definitions and they refer back to the UNC definition, but also the Microsoft File System Control Codes definition for share names. Rather than listing what is allowed, it lists what is illegal, however they equate to exactly the same. It specifically says "All other Unicode characters are legal".

Therefore, I've taken an approach of firstly looking ahead to count the characters - you may want to remove this group from the RegEx if you check the length prior, and then checking the list of non-allowed characters, including all control codes. This may not be quite right according to the standards, however it is practical.

Submitted by thejamesdecker