正規表現(regexpまたはregexとも呼ばれます)は、テキストを検索して置換するためのメカニズムです。1行、1つのファイル、複数のファイル...開発者は、アプリケーションコード、自動テストのテスター、またはコマンドラインで作業するときにそれらを使用します。
単純な検索よりも優れているのはなぜですか?テンプレートを設定できるもの。
たとえば、生年月日はDD.MM.YYYYYの形式で入力されます。さらに転送する必要がありますが、YYYY-MM-DD形式です。簡単な検索でこれを行うにはどうすればよいですか?日付が何になるかは事前にわかりません。
« - ».
?
, test ( )
grep-
...
— , . , . 200, . ( Notepad++ ).
, . .
. , — , , , . :
,
. — , .
: , ,
Regex:
: , ,
, regex, . BACKGROUND-COLOR , ( ) , , regex :
, «», «». !
, , . JavaScript i, . (notepad++) «Match case». , . , , .
, ?
: , , ,
Regex:
: , , ,
. JavaScript g (global), , .
, , ? :
: , 55,
Regex:
: , 55,
. . , , , - . - ... ? . ?
, «». , , :
Regex:
:
, . . , , . , .
. — ().
:
Regex: .
:
, , , . , :
6
&
! , — , . , ? ?
!
Regex: file.
:
file.txt
file1.txt
file2.xls
, ? , txt :
Regex: .txt
:
file.txt
log.txt
file.png
1txt.doc
one_txt.jpg
, txt , «» , «txt» . , ( ).
, — :
Regex: \.txt
:
file.txt
log.txt
file.png
1txt.doc
one_txt.jpg
. ? .
:
. —
\. —
, «», «» . , , :
Regex: ..
:
74
^&
, . , :
Regex: [][]
:
74
^&
! , «», .
? . , :
[] — «» «»
[-] — «» «» ( «»)
[-] —
[--] —
[a-z] —
[a-zA-Z] —
[0-9] —
[-] — «» «» (, — )
[--] — «» «» «» «»
— , ! , — .
[] — «», «» «»
[ ] — «», «», «», ( )
[, , ] — «», «», «»,
— . — , :
—
—
! , ! , - [1-31]. , 1 31, :
1 3
1
. , 1 31! . , , . ! , ! , - =)) ...
:
Regex: . [-]
:
«.»:
6
&
^ [] :
[^0-9] — ,
[^] — , «»
[^-8] — , «», «», «» 8
, txt , — :
Regex: [^0-9]\.txt
:
file.txt
log.txt
file_1.txt
1.txt
, :
Regex: fruits[0]
: fruits0
: fruits[0]
« «fruits», 0». — , .
0- , :
Regex: fruits\[0\]
: fruits[0]
: fruits0
, !
Regex: fruits\[[0-9]\]
:
fruits[0] = “”;
fruits[1] = “”;
fruits[2] = “”;
:
cat[0] = “ ”;
, «» , ...
! , . -? .
, . :
— , !
, . , . ... , . , , .
« », ( — , ...), , !
— fruits\[[0-9]\]
— «fruits».
. , - .
? . , — «fruits[»
. — , . .
. : [0-9]. . . 10, 11 325, ( ) .
: fruits[« »
. .
— ]
: fruits[« »]
! , , ... :
Regex: fruits\[[0-9]\]
:
fruits[0] = “”;
fruits[1] = “”;
fruits[9] = “”;
:
fruits[10] = “”;
fruits[325] = “ ”;
, .
? ..:
2
-
2
-
4
: [0-9][0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9].
, [1-31]. « 1 31», « 1 3, 1». .
, . , ? regexp?
! 8888 99 , ?
Regex: [0-9][0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9]
:
01.01.1999
05.08.2015
:
08.08.8888
99.99.2000
:
31 — [0-3]
12 — [01]
19.., 20.. — [12], [09]
, , . , , , , «9999» «99» ...
, :
Regex: [0-3][0-9]\.[0-1][0-9]\.[12][09][0-9][0-9]
:
08.08.8888
99.99.2000
:
33.01.2000
01.19.1999
05.06.2999
. 31 , 39. , . , .
[] . , — |.
Regex: ||
:
:
. —
Regex: (|)
:
. «», «». ? , . — «», «»:
Regex: |
:
«» «», . .
2 :
(|)
[]
[], , .
« ». [0-3][0-9], 33, 35, 39... !
. ---... :
0 — 1 9 ( 00 )
1, 2 — 0 9
3 — 0 1
:
0[1-9]
[12][0-9]
3[01]
! : 0[1-9]|[12][0-9]|3[01]
. =)
, , , :
(<>)\.(<>)\.(<>)
— . ? , . , , :
[0-1][0-9]\.[12][09][0-9][0-9]
, :
0[1-9]|[12][0-9]|3[01]\.[0-1][0-9]\.[12][09][0-9][0-9]
?
0[1-9]
[12][0-9]
3[01]\.[0-1][0-9]\.[12][09][0-9][0-9]
? «19» . , | . , . , .
— , !
Regex: (|||)
:
:
Regex: |||
:
, :
— []
— |
, [0-9].
, [--a-zA-Z].
?
! , :
|
|
|
\d |
[0-9] |
|
\D |
[^0-9] |
|
\s |
[ \f\n\r\t\v] |
|
\S |
[^ \f\n\r\t\v] |
|
\w |
[[:word:]] |
|
\W |
[^[:word:]] |
, |
. |
|
|
, . «». \d — . « »? :
|
|
|
|
\r |
(Carriage return, CR) |
\n |
(Line feed, LF) |
\t |
(Tab) |
\v |
(vertical tab) |
\f |
(Form feed) |
[\b] |
1 (Backspace) |
— «\r\n». :
:
\r\n
backspace ? ? . ! - ? , — , [\b]?
— . backspace — ASCII , (ASCII code 8, 10 octal). «» , ( JavaScript):
console.log("abc\b\bdef");
:
adef
«abc», «b» «». , . . , . [\b] .
:
What's the use of the [\b] backspace regex? —
, \s, , , .
, . [[:word:]]? . , , . :
|
|
[[:alnum:]] |
: [--a-zA-Z0-9] |
[[:alpha:]] |
: [--a-zA-Z] |
[[:digit:]] |
: [0-9] |
[[:graph:]] |
(, . . ) |
[[:print:]] |
|
[[:space:]] |
[ \f\n\r\t\v] |
[[:punct:]] |
: ! " # $ % & ' ( ) * + , \ -. / : ; < = > ? @ [ ] ^ _ ` { | } |
[[:word:]] |
: [--a-zA-Z0-9_] |
, .., :
[0-9][0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9]
↓
\d\d\.\d\d.\d\d\d\d
, =))
:
[ ] \ / ^ $ . | ? * + ( ) { }
, \ ( ).
Regex: 2\^2 = 4
: 2^2 = 4
Regex: \Q{ ?}\E
: { ?}
( )
. , email-. :
test@mail.ru
olga31@gmail.com
-
? , , . email — «@» «.».
:
/ / _
@
/ / _
-
-
, «\w», (test), (olga31), (pupsik_99). — , . — 2 , 2 , 4 . 2, 22 .
— , .
«+» « », , ! : \w+@
\w, . : \w+@\w+\.
, \w. , . , email :
Regex: \w+@\w+\.\w+
:
test@mail.ru
olga31@gmail.com
pupsik_99_and_slonik_33_and_mikky_87_and_kotik_28@yandex.megatron
, «+»?
|
|
? |
|
* |
|
+ |
|
* — , , «.*» — .
Regex: .*\d\d\.\d\d\.\d\d\d\d.*
:
01.01.2000
09.08.2015! !
! «.*» , :
Regex: .*@.*\..*
:
test@mail.ru
olga31@gmail.com
pupsik_99@yandex.ru
:
@yandex.ru
test@.ru
test@mail.
\w, .
-, — log, log1, log2… log133, * :
Regex: log\d*\.txt
:
log.txt
log1.txt
log2.txt
log3.txt
log33.txt
log133.txt
( ) — , , :
Regex: ?
:
, :
Regex: ()*()*
:
( — , )
, .
, ? , . « » — \d\d\.\d\d\.\d\d\d\d.
2-4 , 10? ? 10 ? . * :
Regex: \d*\.\d*\.\d*
:
.0.1999
05.08.20155555555555555
03444.025555.200077777777777777
, :
|
|
{n} |
n |
{m,n} |
m n |
{m,} |
m |
{,n} |
n |
, \d n , :
\d\d\.\d\d\.\d\d\d\d
\d{2}\.\d{2}.\d{4}
. — , .
— !
Regex: test{2}
: testt
: testtest
, :
Regex: (test){2}
: testtest
: testt
, , , :
Regex: x\{3\}
: x{3}
, .
Regex: <.*>
:
<req>
<query></query>
<gender>FEMALE</gender>
:
<req> <query></query> <gender>FEMALE</gender></req>
HTML XML , , .
, . — . .
, , , :
,
(, . lazy) — , .
? :
<[^>]*>
, , , «>», . . , — , , .
|
|
* |
*? |
+ |
+? |
{n,} |
{n,}? |
« ».
Regex:
:
, . .
, , :
Regex: №\d+ \d\d:\d\d
: №555 15:30
: №555 15:30
:
Regex: .* .*
: ...
: ...
, ? : « .», «...:».
, \b, . , :
Regex: \b\b
:
:
— « , - »:
Regex: \b
:
:
— « , - »:
Regex: \b
:
:
\B, - :
Regex: \B\B
:
:
, , :
^ — ()
$ — ()
, , :
Regex: ^ !$
:
!
:
! !
! !
, :
|
|
\b |
|
\B |
|
^ |
() |
$ |
() |
, — «»: «! ». , .
. ? . - , . , .
Regex: [ ]+(\w+)[]+\1
: ! . .
, :
[ ]+ → , . , \b.
(\w+) → , . «+» , . , , , . , , . , . , — 1.
[ ]+ → .
\1 → 1. . JavaScript-.
: .
|
|
JavaScript vi |
\ |
Perl |
$ |
PHP |
$matches[1] |
Java Python |
group[1] |
C# |
match.Groups[1] |
Visual Basic .NET |
match.Groups(1) |
? , HTML, ? , ?
, :
<h2> 2- </h2>
<h3> 3- </h3>
:
<h2> 2- </h3>
- , . «» .
|
|
|
|
(?=) |
|
(?=11) |
11 113
|
(?!) |
( ) |
(?!11) |
1
511 |
(?<=) |
|
(?<= ) |
|
(?) |
( ) |
( ) |
|
— , ! — :
RegEx:
:
: , !
: , !
, ? , . . ? . .
— . . — , . 1.
RegEx: () \+
: $1
: +
:
« + » ( , , , ). — , , «».
:
RegEx: () \+
: $1
: , + !
: , !
, :
RegEx: () \+ ()
: $2 - $1
: +
: —
— «, - !», ( ). «».
, , . :
RegEx: ^(, ).*(!)$
: $1$2
( ):
, !
, 777!
:
, !
, .
^ — .
. — , . 1. , . «, »
«.*» — . . , .
. — , , . ? — «!».
$ — .
, .
$1 — 1. «, ».
— . , 1, «$1», «,».
$2 — 2, «!»
!
, ? .., --.
— «\d{2}\.\d{2}\.\d{4}». , . :
..
↓
--
, . : (\d{2})\.(\d{2})\.(\d{4})
— . : $3
, : $3-
. , «$2». : $3-$2
, : $3-$2-
, , . , $1. : $3-$2-$1
!
RegEx: (\d{2})\.(\d{2})\.(\d{4})
: $3-$2-$1
:
05.08.2015
01.01.1999
03.02.2000
:
2015-08-05
1999-01-01
2000-02-03
— , 12 . «done», ! « ?», . .
:
—
— « », ,
( )
10-25. . ? ! , .
, , . , — .
:
RegEx: \d+\. (.*)
: $1
:
1.
2.
:
. 5 . — !
=)
10 . — ! , , , . 100 , .
— https://ru.wikipedia.org/wiki/_. , . . , , , . , .
— https://tproger.ru/articles/regexp-for-beginners/
— . , :
.
Grep- — , .
, — ? - ?
, .
— ?
.
...
, , . . .
: « . ». , . .
, , ! , rm ( linux). , , , .
PS- 「役に立つ」というタグの下で私のブログでもっと役立つ記事を探してください。そして、便利なビデオは私のユーチューブチャンネルにあります