File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -20,12 +20,12 @@ def reverse_string(text: str) -> str:
20
20
return text [::- 1 ]
21
21
22
22
23
- def extract_alphanumeric (text : str ) -> str :
23
+ def extract_alphanumeric (s : str ) -> str :
24
24
"""
25
25
Extracts only alphanumeric characters from the given string
26
26
27
27
Args:
28
- text (str): The input string
28
+ s (str): The input string
29
29
30
30
Returns:
31
31
str: String containing only alphanumeric characters
@@ -35,5 +35,9 @@ def extract_alphanumeric(text: str) -> str:
35
35
'HelloWorld123'
36
36
>>> extract_alphanumeric("@#$% abc 123")
37
37
'abc123'
38
+ >>> extract_alphanumeric("こんにちは123ABCワールド")
39
+ '123ABC'
38
40
"""
39
- return "" .join (char for char in text if char .isalnum ())
41
+ # isascii() ensures we only get ASCII characters (0-127),
42
+ # excluding Unicode characters like Japanese, Emoji, etc.
43
+ return "" .join (c for c in s if c .isascii () and c .isalnum ())
You can’t perform that action at this time.
0 commit comments