Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

正则表达式-大小写转换的问题

想直接利用正则实现大小写转换,但 U、L 这样的表达式在 js 中没有效果?对 idea 这样的替换工具是有用的。

"foo_bar".replace(/(_)([a-z]{1})/,"U$2")
--> "fooUbar"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
"foo_bar".replace(/_([a-z]{1})/,function(s,s1){return s1.toUpperCase()})

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...