Replace special characters in the report name with regular expressions (recommended) and special characters in Regular Expressions

Source: Internet
Author: User
Tags expression engine

Replace special characters in the report name with regular expressions (recommended) and special characters in Regular Expressions

A regular expression, also known as a rule expression. (English: Regular Expression, often abbreviated as regex, regexp or RE in code), a concept of computer science. Regular tables are usually used to retrieve and replace texts that conform to a certain pattern (rule.

Many programming languages Support string operations using regular expressions. For example, a powerful Regular Expression Engine is built in Perl, And the built-in java language is also used. The concept of regular expressions was initially popularized by tools in Unix (such as sed and grep. Regular Expressions are abbreviated as "regex". The singular values include regexp and regex, And the plural values include regexps, regexes, and regexen.

// Expression object Pattern p = Pattern. compile ("[\\\\? \ * \: \ [\] \/] "); // Create a Matcher object Matcher n = p. matcher (systemName); Matcher m = p. matcher (unitCodeName); // replace String sheetNameSystem = n. replaceAll (""); String sheetNameUnit = m. replaceAll ("");

The following describes how to replace all special characters with Java regular expressions.

The Java Regular Expression replaces all special characters as follows:

/*** Replace all special characters with regular expressions * @ param orgStr * @ return */public static String replaceSpecStr (String orgStr) {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 section describes how to use regular expressions to replace special characters in the report name to simulate background data login, if you have any questions, please leave a message and the editor will reply to you in time. Thank you very much for your support for the help House website!

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.