几个常用正则表达式

1. replace all ‘\’ to ‘/’ in String(Java and JavaScript)

String(var) origin = “Document\File\pdf\2ad59caf-0cad-4937-996e-113ad4a7b465sok.pdf”;
I want to replace all ‘\’ to ‘/’.

java:

String dest = origin.replaceAll(“\\\\”, “/”);

javascript:

var dest = origin.replace(/\\/g,”/”);

dest=”Document/File/pdf/2ad59caf-0cad-4937-996e-113ad4a7b465sok.pdf”

2. replace ‘/’ to ‘\’

String filepath = “D:\Java\u/c\www/201311/07155109vgm0.jpg”;

filepath = filepath.replaceAll(“/”, “\\\\”);

3. 验证电话号码:

1)/^(\d{3,4}-)?\d{7,9}$/g :[区号-]电话号码

2)/^\d{3,4}-\d{7,8}(-\d{3,4})?$/ :区号-电话号码-分机号

4.验证手机号:

/^0*(13|15|18)\d{9}$/

5.验证邮编:

/^\d{6}$/

This entry was posted in Computer, Java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s