A string that is known to be #####, now needs to replace the # of the even position with .function Replacedemo () { var s = "1#2#3#4#5#"; var regex =/#/g; var index = 1; S=s.replace (regex,function() {index++; Return index%2? ' ': Arguments[0]}); return s; } Comments:1. Because the entire string needs to be matched, the policy expression needs to add the G parameter.2.index is used to record the position of a character matched to a regular expression to find the c
PHP removes the entire directory that matches the criteria, matches the entire directory
PHP
/** * @name The Delfile function is used with the Deldir function to delete the entire directory that matches the condition * @param string $path Specify the action path * @return Null * @example deldir (' D:\web\Apache\htdocs\KeyShareMall\Pc\ThinkPHP '); */ D
The JavaScript Regular Expression matches the div style tag, and the regular expression matches the div
Test string:
abcdefg
First Attempt: a newline character cannot be matched because it matches any character except the linefeed (/n.
Second Attempt:
To match
1. Only Replace the first matching
var result= testData.replace(
2. All
var result= testData.repl
The regular expression matches the user password, and the regular expression matches the user password.
The password format can be set based on the development requirements. The following is an example of password matching:
Regular Expression ^ [a-zA-Z] \ w {5, 17} $
It must start with a letter and be 6 ~ It can only contain characters, numbers, and underscores.
Mismatch
Regular Expression ^ (? =. * \ D )(?
Many articles have been turned over the internet ... Actually not a useful one. I found a Java one, but Java's regular expressions are a bit different from Python's.The article in Java is "[keywd1]| [keywod2]| [KEYWD3] "mode to match, this is not in the PY, [] will match [] any one of the words.In Python, it should be "KEYWD1|KEYWD2|KEYWD3" on the line.Then I personally like to use Re.findall directly () such a parameter is to match the character pattern, and the other is to match the text. More
Use of metacharactersRe.findall (regex,string)Function: In a string string, match the regex regular expression to match the item, and put it in a list to return* Normal stringMetacharacters: ABCMatching rules: matching string valuesMatch example: ABCIn [3]: Re.findall (' abc ', ' Abcdeabc ')OUT[3]: [' abc ', ' ABC ']* use "or" to make multiple matchesMetacharacters: Re1 | Re2Matching rules: Can match the expression of the regular expression Re1, but also can match the content expressed by Re2Mat
Two-part picture lecture hall----------complete the maximum number of matches (minimum number of covers), maximum independent number, minimum path coverage, weighted optimal match (RPM)
Text Content frame:
§ 1 Concepts and properties of arguments, edge sets and binary graphs
§ 22 Maximum matching solution of the graph
Hungarian algorithm, Hopcroft-karp algorithm
§ 32 The construction of the minimum covering set and the maximum independent set of graph
1 Packagetest1;2 3 ImportJava.util.regex.Matcher;4 ImportJava.util.regex.Pattern;5 6 Public classTestexp {7 /**8 * 9 * When using regular expressions, we often use () to enclose a part, called a sub-pattern. There are two cases of capturing and non-capturing in the sub-mode. Ten * Capturing means get match: One * means that the system will save all sub-pattern matching results behind the scenes for us to find or replace them. Use such as a back reference (applying the preceding matche
JS regular implementation matches and processes specific information from a complex HTML code stringProblem:Now to find a particular piece of information from a complex HTML code string (including various HTML tags, numbers, Chinese, and so on) (a pair of "|" wrapped), and he was added to the coarse, plus the line processing.Solution Ideas:1. Match "|" with regular The number of occurrences, processing occurs exactly 2 times (the HTML string generally
(.*?) Match all strings
such as using
Will get num
However, if a newline character is invalidated, and if a match is required, including a newline character, use the
([\s\s]*)
If you have parentheses or other metacharacters in an expression, you need to use escape. Before the character, add a \
Metacharacters
Description
Example
^
Matches the starting position of the entire string, or the starting position of t
) # Trainimage sift = Cv2. SIFT () kp1, des1 = Sift.detectandcompute (IMG1, none) kp2, Des2 = Sift.detectandcompute (Img2, None) # Brute force matching algorithm, two parameters, Distance metric (L2 (default), L1), whether cross matching (false) BF = Cv2. Bfmatcher () #返回k个最佳匹配 matches = Bf.knnmatch (Des1, Des2, k=2) # CV2.DRAWMATCHESKNN expects list of lists as Mat
Ches. #opencv2.4.13 does not have the DRAWMATCHESKNN function, you need to put the
Shell grep matches ChineseTest text demo_exe.c, content as follows, need to pay attention to the saved encoding format, the output to the terminal has an impact:Our Chinese operating system Asni by default is GBK.1#include 2#include 3#include string.h>4#include 5#include 6#include 7 8 /*9 * Export ld_library_path= $LD _library_path:/data/local/tmp;/data/local/tmp/demo_exeTen */ One intMainintargcChar**argv) { A //this is Chinese . - void*handle =
Test instructions: There are two machines, there are several working areas, there are several tasks, can be completed in one area of two machines, two machines start in 0 areas, each change area, will be restarted once, let us find the minimum number of restarts.Idea: Connect two areas, use a binary map, find the maximum number of matches, easy to understand, just the minimum number of restarts.Note: 01 has been completed at the beginning and should n
have two DNA sequences S1 and S2, and the maximum match for S1 and S2 is the length of the longest common sub-sequence of S1 and S2. [Task] Write a program:? Read two equal-length DNA sequences from the input file; Calculate their maximum match;? Print the results you get from the output file. The first line in the input file has an integer n, indicating that some species on the planet use n different bases, and they are numbered 1 later ... An integer of N. There are two lines below, each of w
// ? The meaning of the number is matched 0-1 times, if need to match? How to do
var
reg:tperlregex;
Begin
Reg: = Tperlregex.create (nil);
Reg. Subject: = ' How are you? It's ok! ';
Reg. RegEx : = ' \?|! ';//Gar with \
Reg. Replacement: = ';
Reg. ReplaceAll;
ShowMessage (Reg. Subject); Return: How are you doing?
Freeandnil (reg);
End;
The use of escape symbols \ is sometimes possible, but sometimes problems, it is best not to use
var
reg:tperlregex;
Begin
Reg: = Tpe
Examples of the application of Java's regular expressions (see Java's application of the regular Expressions): Test code packagetest;/** * In string matches () method, the split () method uses regular expressions . * @author fhd001 */ publicclassregextest{ public Staticvoidmain (String[]args) { /* * Ordinary characters */ Stringstr1= "abc45abc345"; String[]arr1=str1.split ("abc"); for (STRINGNBSP;STRINGNBSP;:NBSP;ARR1) { system.out.print (st
In the course of the interview encountered a topic such as:For example, there is an HTML string:var string= ' The HTML tag has In fact, the regular expression matching HTML tags is very short, as follows:That's it, it's gone? Yes. Are you surprised?This regular expression is also collected in the network, but I can understand, first of all, the HTML tag is definitely starting with the any more than 1 characters apart from the > Symbol ".Examples are as follows:var string= 'class ' test '>test a
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.