Base64 String Regex
Matches Base64 encoded strings.
パターン
/\b[A-Za-z0-9+/]{4}(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\b/g
→ ビジュアライザーで開くテスト例
Encoded: SGVsbG8gV29ybGQ= and data: dGVzdA==
コード例
javascript
const regex = /\b[A-Za-z0-9+/]{4}(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\b/g;
const result = str.match(regex);python
import re
pattern = re.compile(r'\b[A-Za-z0-9+/]{4}(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\b')
result = pattern.findall(text)go
import "regexp"
re := regexp.MustCompile(`\b[A-Za-z0-9+/]{4}(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\b`)
result := re.FindAllString(text, -1)base64encodingdata