Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Julia正则表达式使下一个字符大写_Regex_String_Julia - Fatal编程技术网

Regex Julia正则表达式使下一个字符大写

Regex Julia正则表达式使下一个字符大写,regex,string,julia,Regex,String,Julia,如何将字符串中每个单词的第一个字母大写?将\1\U\2用作replace()的一部分会引发错误:错误的替换字符串。正则表达式更可取,但也欢迎使用其他方法。这是我期望的工作,但给出了错误: test_string = "the quick brown fox jumps over the lazy dog" replace(test_string, r"(^|\s)([a-z])" => s"\1\U\2") 您可以使用titlecase函数进行如下操作: julia> test_s

如何将字符串中每个单词的第一个字母大写?将
\1\U\2
用作
replace()
的一部分会引发错误:
错误的替换字符串
。正则表达式更可取,但也欢迎使用其他方法。这是我期望的工作,但给出了错误:

test_string = "the quick brown fox jumps over the lazy dog"
replace(test_string, r"(^|\s)([a-z])" => s"\1\U\2")

您可以使用
titlecase
函数进行如下操作:

julia> test_string = "the quick brown fox jumps over the lazy dog"
"the quick brown fox jumps over the lazy dog"

julia> titlecase(test_string, strict=false)
"The Quick Brown Fox Jumps Over The Lazy Dog"

对于更复杂的情况,您可以定义
wordsep
函数或将
strict
更改为
true
(默认值)。

您可以使用
titlecase
函数进行如下操作:

julia> test_string = "the quick brown fox jumps over the lazy dog"
"the quick brown fox jumps over the lazy dog"

julia> titlecase(test_string, strict=false)
"The Quick Brown Fox Jumps Over The Lazy Dog"

对于更复杂的情况,您可以定义
wordsep
函数或将
strict
更改为
true
(默认值)。

下面是另一个使用
replace
大写
和正则表达式的选项:

replace(test_string, r"(^|\s)([a-z])" => uppercase)

下面是另一个使用
替换
大写
和正则表达式的选项:

replace(test_string, r"(^|\s)([a-z])" => uppercase)