/** * * @author Zen Johnny * @date April 29, 2018 PM 4:31:07 * */package Demo.regex;public class Regexreplacedemo {public S tatic void Replacedemo (String string, string regex,string replacement) {System.out.println (String.replaceall (Regex, replacement));} public static void Main (string args[]) {//case1: As long as the number is more than 5 consecutive, the segment string is replaced with #string string = " Bn45353453assss3444effffewtvdt4efvdfdgf455454ggt5grgfer3 "; String regex = "\\d{5,}+"
PHP Regular Expression full manual, regular expression full manual
Full Manual of regular expressions for PHP
Objective
Regular expressions are cumbersome, but powerful, learned applications will give you an absolute sense of acc
1, Greediness (Greedy type):Maximum MatchX, x*, x+, X{n,} are allmaximum match. For example you want to use "① " 2, reluctant (laziness)(barely type): minimum MatchX, x*, x+, X{n,} are the maximum matches. All right, add one? It becomes a laziness match. For example X??、 x*, x+, X{n,}? are the minimum matches, in fact x{n,m}? and X{n}? Some superfluous. Minimum matching means,. +? After matching a charact
The first method of validation is the pattern P = pattern.compile ("mode");Matcher m = p.matcher ("Information to be verified");Boolean B = m.matches ();The second method of authentication is Boolean B = pattern.matches ("mode", "information to be verified"); Third authentication method Boolean b = src.matches ("^http://.*")For example: To verify that the information string src is in HTTP format, it can be used: Boolean B = pattern.matches ("^http://.
-]+) *@[\\w-]+ (\\.[ \\w-]+) +$ "//email address
"^[a-za-z]+://(\\w+ (-\\w+) *) (\ \\w+ (-\\w+) *)) * (\\?\\s*) $ "//url
"^[a-za-z0-9_]*$"
The use of regular expressions in the detailed
Brief introduction
In short, regular expressions are a powerful tool that can be used for pattern matching and substitution. Its role is as follows:
Tests a pattern of a string. For exam
" in the target object, or "Wilsn", and so on, after the letter I.
Sometimes you don't know how many characters to match. To accommodate this uncertainty, regular expressions support the concept of qualifiers. These qualifiers can specify how many times a given component of a regular expression must appear to satisfy a match.
{n} n is a non-negative integer. Ma
Regular ExpressionsEdit regular expressions, also known as formal representations, general representations (English: Regular Expression, often abbreviated as regex, RegExp, or re) in code, a concept of computer science. A regular express
meaning
{N,m}
Matches the previous item at least n times, but not more than m times
{N,}
Match the previous item at least n times
N
Match the previous top n times
?
Matches the previous item 0 or 1 times, which means the previous item is optional, equivalent to {0,1}
+
Matches 1 or more times before, equivalent to {1,}
*
Matches 0 or more times before, equivalent to {0,}
Here ar
match URL URL:http://([\w-]+\.) +[\w-]+ (/[\w-./?%=]*)?Regular expression that matches the phone number and starts with a number:((\ (\d{3}\)) | (\d{3}\-))? 13\d{9}|15[89]\d{8} or [+]{0,1} (\d) {1,3}[]? ([-]? ((\d) | []) {1,12}) +Match regular telephone, fax number, can "+" start, except number, can contain "-" Regular
clusters
7.3_ OK repeat occurrence
1. Intro
At present, regular expressions have been widely used in many software applications, including *nix (Linux, UNIX, etc.), HP and other operating systems, Php,c#,java and other development environments, as well as many applications, can see the shadow of regular expression.
T
Objective
Regular expression is cumbersome, but powerful, after the application of learning will let you in addition to improve efficiency, will give you a sense of absolute achievement. As long as the careful reading of these materials, coupled with the application of a certain reference, master regular expression is
look at a simple regular expression, today. Although it is plain text, it is a regular expression. Let's look at an example:
Source Text: Yesterday is history, tomorrow is a mystery, but today is a gift.
Regular
, and approximately 3 days after 400 years, thus reducing the 400 leap year in every three years. Leap year calculation, summed up is usually said: four years a leap, hundred years does not leap, 400 year again leap.
2.3 Format of the date
Depending on the language and culture, the hyphen of the date will vary, usually in the following formats:
YyyyMMdd
Yyyy-mm-dd
Yyyy/mm/dd
yyyy. Mm.dd
Regular expression
As with the MySQL comprehensive optimization detailed in the previous writing, it is because such tools are widely used, so a comprehensive optimization strategy for such tools is a good deal, because whether you're a programmer in PHP, Perl, Python, C + +, C #, Java, and so on, You are very likely to use a tool such as MySQL, regular expressions.
Let's say something you may not know. Knowledge of
PHP regular expression full tutorial basics, regular expression full tutorial
At present, regular expressions have been widely used in many software applications, including * nix (Linux, Unix, etc.), HP and other operating systems, PHP, C #,
Regular expressions can:• Test a pattern for a string. For example, you can test an input string to see if there is a phone number pattern or a credit card number pattern in the string. This is called data validation
• Replace text. You can use a regular expression in your document to identify specific text, and then y
At present, regular expressions have been widely used in many software applications, including *nix (Linux, UNIX, etc.), HP and other operating systems, Php,c#,java and other development environments, as well as many applications, can see the shadow of regular expression.
The use of
. The specific descriptions are as follows:
Character
Replace text
$1, $2,..., $99
Text that matches the 1st to 99 subexpressions in regexp
$
String Matching regexp
$'
Text on the left of the matched substring
$'
Text on the right of the matched substring
$
Direct Volume symbol
Let's take a look at the following example:
// 1. Replace with
up of a series of characters. Most characters, including all alphanumeric characters, describe characters that are matched literally. In this case, the regular expression/java/and all of the containing substring "Java" String. Although the other characters in the regular
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.