()) {String output = Matcher.group (); SYSTEM.OUT.PRINTLN (output);}} /** * Output: * DD * DCD *//** * quantifier suffix? , * match the number of X (? is the suffix of the quantifier of X), if the match is guaranteed to be successful; * Same as Default */@Testpublic void Test5 () {String regex = "D[a-z]*?d"; String input = "1DDCCBDCCCCD2DCD"; Pattern pattern = pattern.compile (regex); Matcher Matcher = pattern.matcher (input); while (Matcher.find ()) {String output = Matcher.group (); SYSTEM.OU
Greediness (greedy type): Maximum matchX, x*, x+, X{n,} are the maximum matches. For example you want to use "In the greediness mode, the match will be as large as possible until the entire content is matched, and when the match is found to be unsuccessful, the fallback narrowing the match until the match is successfulString test = "A= ""# # #");Output: a## #abbReluctant (laziness) (barely): Minimum matchX??、 x*, x+?, X{n,}? Is the minimum match, in fact x{n,m}? and X{n}? Some superfluous. Add a
The instance is as follows:
public static string Repdomain (string source, string domain, string element, string attr
) {String img = "";
Pattern P_image;
Matcher M_image; String regex_img = "
The above is the Java regular expression for everyone to get the specified value of the specified attribute of the HTML tag and replace the
Occasionally found Dongdong, do not remember is that the Bolg. Very good article ....
§1 Dark Years
There is a string, how do I find out if there are Y and F characters? The darkest way is to:
Program 1: I know if, for statements, and Charat ().
Class test{public static void Main (String args[]) {String str= "For my money, the important thing" +"About the meeting is bridge-building";Char x= ' y ';Char y= ' f ';Boolean result=false;for (int i=0;iChar Z=str.charat (i); System.out.println (z);
for(inti = 0; i ) { the //ensure that a continuous string B matches a segment in a the if(A_t[i] = = B_t[j] J b_t.length) { thetemp++;117J + +;118 //The continuous string b matches a segment in a119 if(temp = =b_t.length) { -count++;121temp = 0;122j = 0;123 }124 } the //as long as there is a character mismatch, the temp count is never126 Else {127temp = 0; -j = 0;129 } the
Note: 1. [] represents the character set, does not represent the inclusion () Table capture and group Eg: can only be QQ mailbox/gmail mailbox/outlook Mailbox/163 mailbox One (qq|gmail|163) {1}\.com and [QQ] | ( Gmail) | (163)] \.com; the latter is wrong. Constructs a match character X character x\\ backslash character \0n with octal value 0 characters n (0 Regular expression six: matching rules for
A colleague from C + + asked me to help write a regular expression: Verify that a value is a number. I simply wrote one in Java code.
public class Test {public static Boolean CheckNumber (double value) {String str = string.valueof (value); String regex = "^" (-?[ 1-9]\\d*\\.? \\d*) | (-?0\\.\\d*[1-9]) | (-? [0]) | (-?
[0]\\.\\d*] $ ";
return str.matches (rege
S:arr) * { $ Ts.add (s);Panax Notoginseng } -Regex= "0* (\\d+)"; the for(String s:ts) + { ASystem.out.println (S.replaceall (Regex, "$")); the } + } -}View CodeOperation Result:1 192.168.10.34 2 127.0.0.1 3 105.70.11.75 4 3.3.3.3 5 6 7 192.168.010.034 8 127.000.000.001 9 105.070.011.075 003.003.003.003 A 3.3.3.3 105.70.11.75 127.0.0.1 192.168.10.34 View CodeWhen the extra 0 is removed, the mode used is: "0* (\\d+)", so that even if all is 0, the
ImportJava.util.regex.Matcher; ImportJava.util.regex.Pattern; Importjava.util.regex.PatternSyntaxException; Public classPhoneformatcheckutils {/*** Mainland or Hong Kong numbers are available*/ Public Static BooleanIsphonelegal (String str)throwspatternsyntaxexception {returnIschinaphonelegal (str) | |Ishkphonelegal (str); } /*** Mainland Mobile phone number 11 digits, match format: first three bit fixed format + 8 digits any number * This method in the first three bit format has:
/** * * @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,}+"
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.