
Get Started > Details
- Details
- Install
Deskripsi.
Regex, atau regular expression, adalah urutan karakter yang digunakan untuk mencocokkan dan mencari pola teks dalam string. Regex memungkinkan Kamu untuk mencari, mengganti, atau memvalidasi teks berdasarkan pola tertentu. Ini adalah alat yang kuat untuk manipulasi dan analisis teks dalam pemrograman.
Ini beberapa kode Regex yang saya sering gunakan.
Dalam Format Tahun
- 2001
- 2002
- 2003
- 2004
- Other
/^[0-9]{4}$/
Dalam Format Score
- 1.1
- 2.0
- 9.9
- 5.5
- Other
/^\d+(\.\d{1,2})$/
Dalam Format Musim
- Winter 2001
- Spring 2001
- Summer 2001
- Fall 2001
- Other
/^([Ww]inter|[Ss]pring|[Ss]ummer|[Ff]all) [0-9]{4}$/
Dalam Format Menit
- 23 min
- 20 min
- 4 min
- 19 min
- Other
/^[0-9]{2} [Mm]in$/
Dalam Chapter
- Chapter 01
- Chapter 1.1
- Chapter 2
- Chapter 4.6
- Other
/[cC]hapter\s(\d+(\.\d+)?)/
<a class='c-999' expr:href='data:post.url' itemprop='item'>
<span itemprop='name'>
<script type='text/javascript'>
// Extract chapter information from the post title using regular expression
var chapterRegex = /\bChapter (\d+\s*[^\n\r]*)/i;
var match = chapterRegex.exec('<data:post.title/>');
if (match) {
document.write(match[1]);
} else {
document.write('<data:post.title/>');
}
</script>
</span>
</a>
<meta content='3' itemprop='position'/>
</li>
<a class='c-999' expr:href='data:post.url' itemprop='item'>
<span itemprop='name' id='chapterName'></span>
<script type='text/javascript'>
// Extract chapter information from the post title using regular expression
var name = '<data:post.title/>';
var chapterRegex = /\bChapter\s(.*)/i;
var match = chapterRegex.exec(name);
var chapterName = match ? match[0] : name;
// Update the content of the span element with the extracted chapter name using textContent
var t_chapterName = document.getElementById('chapterName');
t_chapterName&&(t_chapterName.textContent=chapterName);
</script>
</a>
<meta content='3' itemprop='position'/>
</li>