Regular Expression Problems

Source: Internet
Author: User

Today, there is another problem with promote baseline, and Paul made some changes.

Regular Expression eight principles: (http://www.aka.org.cn/Lectures/002/Lecture-2.1.2/perl-reg.html)

· Principle 1: regular expressions have three different forms (matching (M //), replacement (S // EG), and conversion (TR ///)).

· Principle 2: Regular Expressions only match scalar values ($ scalar = ~ M/A/; can work; @ array = ~ M/A/will treat @ array as a scalar, so it may not succeed ).

· Principle 3: Regular Expressions match the earliest possible match of a given pattern. Lack of time, only match or replace the regular expression once ($ A = 'string string2'; $ A = ~ S/string //; causes $ A = 'string 2 ').

· Principle 4: Regular Expressions can process any and all characters that double quotation marks can process ($ A = ~ M/$ varb/extend varb to a variable before matching. If $ varb = 'A' $ A = 'as', $ A = ~ S/$ varb //; equivalent to $ A = ~ S/A //;, the execution result is $ A = "S ").

· Principle 5: the regular expression produces two situations in the value evaluation process: Result Status and reverse reference: $ A = ~ M/pattern/indicates whether the child string pattern appears in $ A, $ A = ~ S/(word1) (word2)/$2 $1/the word "change.

· Principle 6: the Core Competence of Regular Expressions lies in wildcards and Multiple matching operators and how they operate. $ A = ~ M/\ W +/matches one or more word characters; $ A = ~ M/\ D/"matches zero or multiple numbers.

· Principle 7: To match more than one character set, Perl uses "|" to increase flexibility. If M/(cat | dog)/is input, it is equivalent to "matching string cat or dog.

· Principle 8: Perl (?..) The Syntax provides extended functions for regular expressions.

Question 1:
From "m_x75plat_mp-Main_1.0_v118: Project: mc75p #1 ", extract" _ 1.0 _ v118 "and splice it into" cmt_x75plat_1.0_v118_060221"
Or from "m_x75plat_mp-MEC # main_1.0_v15.1: Project: mc75p #1 ", extract" _ 1.0 _ v15.1 "and splice it into" cmt_x75plat_1.0_v15.1_060221"

If ($ version = ~ /#/){
($ Baseline = $ version) = ~ S/^ (. *) \ # (. *) \ s * $ */CMT _ $2 _ $ date /;
} Else {
$ Baseline = "CMT _". $ version. "_". $ date;
}

$ Baseline = $ out;
Chomp $ baseline;
$ Out = ~ S/^ (. *) \-(. *) \ :(. *) \ :(. *) \ s */$2 /;
If ($ out = ~ /#/){
$ Baseline = ~ S/^ (. *) \-([^-] +) \ # (. *) \ :(. *) \ :(. *) \ s */$3 /;
} Else {
$ Baseline = ~ S/^ (. *) \-(. *) \ :(. *) \ :(. *) \ s * $*/$2 /;
}

$1, $2. These variables correspond to the preceding ones, and do not need to be replaced with the characters (. *).
For example
$ String = "a B C D E F G ";
$ String = ~ S/(A) (. *) (c d e) (. *)/$2 $4 /;
Print $ string;
Now the running result is
B f g

Related Article

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.