Non-Greedy Match Regex
Uses non-greedy quantifier to match the shortest possible string.
パターン
/<.+?>/g
→ ビジュアライザーで開くテスト例
<div><p>Hello</p><span>World</span></div>
コード例
javascript
const regex = /<.+?>/g; const result = str.match(regex);
python
import re pattern = re.compile(r'<.+?>') result = pattern.findall(text)
go
import "regexp" re := regexp.MustCompile(`<.+?>`) result := re.FindAllString(text, -1)
greedyadvancedtutorial