Use regular expressions to replace special characters in report names (recommended) _ Regular expressions

Source: Internet
Author: User

Regular expressions, also known as regular expressions. (English: Regular Expression, often abbreviated as regex, RegExp, or re) in code, a concept of computer science. Regular tables are often used to retrieve and replace text that conforms to a pattern (rule).

Many programming languages support the use of regular expressions for string manipulation. In Perl, for example, a powerful regular expression engine was built, as well as the Java language itself. The concept of regular expressions was initially popularized by tool software (such as SED and grep) in Unix. Regular expressions are usually abbreviated as "regex", singular with regexp, regex, plural with regexps, regexes, Regexen.

Expression object Pattern
p = Compile ("[\\\\?\\*\\:\\[\\]\\/]");
Create Matcher object
Matcher n = p.matcher (systemname);
Matcher m = P.matcher (unitcodename);
Replace
String Sheetnamesystem = N.replaceall ("");
String sheetnameunit = M.replaceall ("");

Look at the following Java regular expressions replace all special characters

The Java regular expression replaces all special characters as follows:

/** 
* Replace all special characters 
* @param orgstr 
* @return/Public 
static string Replacespecstr (String orgstr) { C6/>if (null!=orgstr&&! "". Equals (Orgstr.trim ())) { 
String regex= ' [\\s~ '!! @#¥$%^......&* (()) \ \-—— \\-_=+ "\\[\\]" {{}}\\|, \\\\;;:: "" "\", "<." >,/??] "; 
Pattern p = pattern.compile (regEx); 
Matcher m = P.matcher (ORGSTR); 
Return M.replaceall (""); 
} 
return null; 

The above is a small set for you to introduce the use of regular expressions to replace the special characters in the report name, to achieve a simulated background data login effect, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.