Today began a small series for everyone to organize a series of regular expression of the article, I hope you will like.
First understand the concept of regular expressions, the regular expression (regular
, up to 25 bits, the user name immediately after the @, followed by the domain name, domain names can only contain alphanumeric and minus sign (-), and can not start or end with a minus sign, Then there is the domain suffix (there can be more than one), the domain name suffix must be dot number connected to 2-4 charactersJS CodeCopy CodeThe code is as follows:var re =/^\w{1,15} (?: @ (?! -)) (?:(?: [a-z0-9-]*) (?: [A-z0-9] (?! -))(?:\. (?!-))) +[a-z]{2,4}$/; Articles you may be interested in:
)
Copy Code code as follows:
(?: x) x, as a non-capturing group
(? idmsux-idmsux) Nothing but will match the logo i d m s u x on-off
(? idmsux-idmsux:x) x, as with the given flag I d m s u x on-off
(? =x) X, through a positive lookahead of 0 widths
(?! x) x, through a negative lookahead of 0 widths
(? (? (? >x) X, as a separate, non-capturing group
Backslashes, escapes, and references
The backslash character (' \ ') is used to reference the escaped construct,
1, simple match
In Java, strings can be used directly
String.matches (Regex)
Note: The regular expression matches all of the strings
2, Match and find
Find the substring that matches the regular expression in the string, Matcher the value in the angle bracket with t
JS Regular expression//checksum is all composed of numbers function isdigit (s) {var patrn=/^[0-9]{1,20}$/; if (!patrn.exec (s)) return false return True}//Checksum Login Name: You can only enter 5-20 letters beginning with a letter, with numbers, "_", "." The string Java code function Isregisterusername (s) {var patrn=/^[a-za-z]{1} ([a-za-z0-9]|[. _]) {4,19}$/;
The regular expression verifies the QQ number and the regular expression number.
If you don't talk much about it, paste the Code directly. The specific code is as follows:
Package regular expression;/* verification requirements
done the finite state automatic machine, has already very clear this kind of word processing matter should give regular Expression (regular expression), only oneself always because the regular expression is obscure difficult to u
The multi-row mode and single-row mode graph analysis of the regular expression, the regular expression multiple rows
In Expresso, test "multiline mode"
Test 1
Note: In this example, 3eeeee is not followed by a carriage return, and the cursor is behind e. The matching result is 3 eeeee, as shown in the Search Results
of code creates a new RegExp object and assigns it to the variable parttern. This particular RegExp object matches all strings that end with the letter "s". You can also define theAn equivalent regular expression with the following code:
var pattern = new RegExp ("s$");
It is easy to create a RegExp object whether using a regular
Use a regular expression to match the input content ---- Regular Expression// Use a regular expression to match the input contentPackage regex;Import java. util. collections;Import
character: Regex.match ("string", "Regex", Regexoptions.multiline)
Application: String str = Regex.Replace (Original, "^", ">", Regexoptions.multiline)--Inserts ">" At the beginning of each line.
• Absolute Anchoring
Even if/z and $ only match the end position of the string, there is an exception. If the string ends with a new line character,/z and $ will match the position before the new line character, not the end of the entire string. This "improvement" was introduced by Perl and followed b
Java Regular expressions provide a richer class library and greatly simplify the process. The common basic syntax is listed below:
+ ^ $ [] () | /\ \d \d \w \w {} {n} {n,m}, etc.
Note that the "|" or symbols. It can match a single character and string. such as: T[aeio]n only match Tan,ten,tin,ton. But does not match toon, because in square brackets only can match a single character, to match Toon, use T (A|
, and whenever you find the last match in a string, you start using the same RegExp object to retrieve another string, and the method should be done when you discard the original search. This particular behavior allows you to repeatedly invoke exec () to iterate through all the regular expression matches in a string.
code is as follows
copy code
/* matched '
Parse Apache log file, regular expression
/** Copyright (c) Ian F. Darwin, http://www.darwinsys.com/, 1996-2002.* All rights reserved. Software written by Ian F. Darwin and others.* $Id: license,v 1.8 2004/02/09 03:33:38 Ian Exp $** Redistribution and use in source and binary forms, with or
I've been hearing about regular expressions, especially when I'm learning Java, and I've encountered a lot of regular expressions.Method. For example, you can use regular expressions to restrict what you enter in an input box. Of course, after Android, the regular
expression
A regular expression is a special string pattern used to match a set of strings. It is like using a mold as a product, while a regular expression is the mold, defining a rule to match characters that conform to the rule.
1.2 common
Objective Regular expressions are cumbersome, but powerful, learned applications will give you an absolute sense of accomplishment in addition to improving efficiency. It is not a problem to master regular expressions, as long as you read them carefully, add some references when applying them. Index 1._ Intro2._ The history of regular expressions3._
Regular expressions provide a concise, flexible means of matching text strings, such as specific characters, text, or character styles. It is a headache for beginners to understand and use all the regular expression syntax. Fortunately, you can get online help.
In this article, 10 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.