Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

正则,驼峰下划线互转 #4

Open
zhangyanan0525 opened this issue Jun 9, 2018 · 0 comments
Open

正则,驼峰下划线互转 #4

zhangyanan0525 opened this issue Jun 9, 2018 · 0 comments

Comments

@zhangyanan0525
Copy link
Owner

zhangyanan0525 commented Jun 9, 2018

下划线转驼峰

var str = "foo_style_css";
// 方法1
str.replace( /_([a-z])/g, function( all, one ) {
	return one.toUpperCase();
});
// 方法2
str.replace(/_(\w)/g, function(all, one){
        return one.toUpperCase();
});

驼峰转下划线

var str = 'WelcomeToDidi';
str.replace(/([A-Z])/g,function(all,one){
	return '_'+one.toLowerCase()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant