從字符串 "你好content://media/external/images/media/580376你好" 中提取 content://media/external/images/media/580376。
content[^\u4e00-\u9fa5]*
content:字面匹配開頭標識。[^\u4e00-\u9fa5]:否定字符類,匹配**非** CJK 統一漢字基本區字符(\u4e00-\u9fa5 涵蓋 20902 個常用漢字)。*:貪婪匹配 0 次或多次,直到遇到漢字或字符串結束。| 語言 | 代碼 |
|---|---|
| Java | Pattern.compile("content[^\\u4e00-\\u9fa5]*").matcher(str).results().map(MatchResult::group).findFirst() |
| JavaScript | str.match(/content[^\u4e00-\u9fa5]*/)?.[0] |
| Python | re.search(r'content[^\u4e00-\u9fa5]*', s).group() |
| C# | Regex.Match(s, @"content[^\u4e00-\u9fa5]*").Value |
| PHP | preg_match('/content[^\x{4e00}-\x{9fa5}]*/u', $s, $m); $m[0] |
| Go | regexp.MustCompile(`content[^\u4e00-\u9fa5]*`).FindString(s) |