1
1
"""
2
2
$docstring_str_count
3
3
"""
4
- function str_count (column, pattern:: Union{String,Regex} )
4
+ function str_count (column, pattern:: Union{String,Regex} ; overlap :: Bool = false )
5
5
if ismissing (column)
6
6
return (column)
7
7
end
@@ -11,7 +11,7 @@ function str_count(column, pattern::Union{String,Regex})
11
11
end
12
12
13
13
# Count the number of matches for the regular expression
14
- return length (collect (eachmatch (pattern, column)))
14
+ return length (collect (eachmatch (pattern, column, overlap = overlap )))
15
15
end
16
16
17
17
"""
@@ -111,15 +111,15 @@ end
111
111
"""
112
112
$docstring_str_replace_all
113
113
"""
114
- function str_replace_all (column, pattern:: Union{String, Regex} , replacement:: String )
114
+ function str_replace_all (column, pattern:: Union{String,Regex} , replacement:: String )
115
115
if ismissing (column)
116
116
return column
117
117
end
118
118
119
119
regex_pattern = isa (pattern, String) ? Regex (pattern) : pattern
120
120
121
121
column = replace (column, regex_pattern => replacement)
122
-
122
+
123
123
return replace (column, r" \s +" => " " )
124
124
end
125
125
191
191
"""
192
192
$docstring_str_starts
193
193
"""
194
- function str_starts (string:: AbstractString , pattern:: Union{AbstractString, Regex} ; negate:: Bool = false ):: Bool
194
+ function str_starts (string:: AbstractString , pattern:: Union{AbstractString,Regex} ; negate:: Bool = false ):: Bool
195
195
if ismissing (string)
196
196
return (string)
197
197
end
@@ -202,13 +202,13 @@ function str_starts(string::AbstractString, pattern::Union{AbstractString, Regex
202
202
else
203
203
error (" Pattern must be either a Regex or an AbstractString." )
204
204
end
205
-
205
+
206
206
return negate ? ! match_result : match_result
207
207
end
208
208
"""
209
209
$docstring_str_ends
210
210
"""
211
- function str_ends (string:: AbstractString , pattern:: Union{AbstractString, Regex} ; negate:: Bool = false ):: Bool
211
+ function str_ends (string:: AbstractString , pattern:: Union{AbstractString,Regex} ; negate:: Bool = false ):: Bool
212
212
if ismissing (string)
213
213
return (string)
214
214
end
@@ -219,7 +219,7 @@ function str_ends(string::AbstractString, pattern::Union{AbstractString, Regex};
219
219
else
220
220
error (" Pattern must be either a Regex or an AbstractString." )
221
221
end
222
-
222
+
223
223
return negate ? ! match_result : match_result
224
224
end
225
225
@@ -278,10 +278,10 @@ end
278
278
"""
279
279
$docstring_str_extract
280
280
"""
281
- function str_extract (input:: AbstractString , pattern:: Union{String, Regex} )
281
+ function str_extract (input:: AbstractString , pattern:: Union{String,Regex} )
282
282
# Convert pattern to Regex if it's a string
283
283
regex_pattern = isa (pattern, String) ? Regex (pattern) : pattern
284
-
284
+
285
285
# Find the first match, return missing if none found
286
286
m = match (regex_pattern, input)
287
287
return m === nothing ? missing : m. match
@@ -290,14 +290,13 @@ end
290
290
"""
291
291
$docstring_str_extract_all
292
292
"""
293
- function str_extract_all (string:: AbstractString , pattern:: Union{String, Regex} )
293
+ function str_extract_all (string:: AbstractString , pattern:: Union{String,Regex} )
294
294
# Convert pattern to Regex if it's a string
295
295
regex_pattern = isa (pattern, String) ? Regex (pattern) : pattern
296
-
296
+
297
297
# Collect matches
298
298
matches = [String (m. match) for m in eachmatch (regex_pattern, string)]
299
-
299
+
300
300
# Return missing if no matches found
301
301
return isempty (matches) ? missing : matches
302
302
end
303
-
0 commit comments