1 | import os |
1 | import os |
1 | import os |
1 | import os |
Create a regular expression that matches a comma-delimited list of the words one,
two, and three. Each word can occur any number of times in the list, and the words
can occur in any order, but each word must appear at least once.
\b(?:(?:(one)|(two)|(three))(?:,|\b)){3,}(?(1)|(?!))(?(2)|(?!))(?(3)|(?!))
First an words anchor, then no capture group, inside three possible group anticipate be matched.
Behind is a comma ,
or an anchor, these pattern happen at least three times.
If group 1th
2th
3th
group exists then txt matched.
if not then (?!)
anticipate it’s back is not a null, so definitely fail, no matched.
\b(?:(?:(one)|(two)|(three))(?:,|\b)){3,}
(?(name)then|else)
(?(<name>)then|else)
or (?('name')then|else)
(?(?=if)then|else)
or (?(?<=if)then|else)
(a)?b(?(1)c|d)1
matches abc
and bd
(a)?b(?(?<=ab)c|d)
matches abc
and bd
lookaround can be written without the conditional as (?=if)then|(?!if)else
(a)?b((?<=ab)c|(?<!ab)d)
matches abc
and bd
(?<=<b>)\w+(?=</b>)
JavaScript and Ruby 1.8 support the lookahead (?=</b>)
, but not the lookbehind (?<=<b>)
Essentially, lookaround checks whether certain text can be
matched without actually matching it.
lookbehind (?<=…) is the only regular expression construct that
will traverse the text right to left instead of from left to right
Lookaround constructs are therefore called zero-length assertions.
(?!...) (?<!...)
, with an exclamation point
instead of an equals sign, is negative lookaround.
negative lookaround
matches when the regex inside thelookaround
fails to match.
lookahead is completely compatible, even
lookahead or lookbehind nested in lookahead.
lookbehind is different, because regex is design traverse
from left to right, but lookbehind needs right to left
Perl
and Python
still require lookbehind to have a fixed length
PCRE
and Ruby 1.9
allow alternatives of different lengths inside lookbehind
notepad++ use PCRE7.2
regular expression engine?
Java
takes lookbehind one step further, allows any finite-length
regular expression ‹*›, ‹+›, and ‹{42,}›
inside lookbehind
.NET Framework
is the only one in the world
that can actually apply a full regular expression from right to left.
(?=(\d+))\w+\1
The group capture inside the lookaround is same as usual group,
numbered from outter to inner , left to right
<b>\K\w+(?=</b>)
Match with ‘\K’, string in front of it will not be pattern.
It matches like a block, no recursive, no loop, no backtrack.
For example:
when (?<=a)a
matches the string ‘aaaa’, three a
be matched,
the 2th/ 3th/ 4th a
. Lookbehind will track to left one matched then next.
But a\Ka
matches two a
, the 2th and the 4th.
when first/second a
captured, abandon first, then second matches.
Then begin next matching, third/fourth a
captured, abandon thrid.
In Ruby 1.8 or JavaScript there is no lookbehind can be use.
Solution:
\1
or \kxxx
.1 | var mainregexp = /\w+(?=<\/b>)/; |
<b>
, then lookbehind matched./etc/profile.d
a | b |
---|---|
xset -q | 查询 |
xset s off | 禁用屏幕保护 |
xset s 3600 3600 | 设置空闲时间为1小时 |
xset -dpms | 关闭 DPMS[电源之星] |
xset +dpms | 开启 DPMS[电源之星] |
xset s off -dpms | 禁用 DPMS 并阻止屏幕进入空闲 |
xset dpms force off | 立即关闭屏幕 |
xset dpms force standby | 强制屏幕进入待命状态 |
xset dpms force suspend | 强制屏幕进入暂停状态 |
xset dpms 600 900 1200 | 三个数值分别为 Standby Suspend Off[s] |
Raspbian & Archlinux -> /etc/bash.bashrc
CentOS -> /etc/bashrc
1 | setterm -blank [0-60|force|poke] |
setterm -blank 0 -powerdown 0
No protect mode , no powerdown close display
/etc/rc.local
add command before exit 0
script must have execute authority x
1 | sudo cp -f /home/pi/autowifi.sh /etc/init.d/ |
/etc/init.d
1 | update-rc.d [-n] [-f] name remove |
-n
do nothing, only preview.-f
delete link, even script remain in /etc/init.d
NN
execute sequenceSS
begin sequence KK
end sequence\b[a-f0-9]{1,8}\b
\d*\.\d+(e\d+)?
1 | *? |
In default repeat like *
+
?
{}
after match unit are all greedy[greedy is not selfish]
Possessive quantifiers is greedy and selfish
It’s greedy and selfish, when it matches, it wouldn’t care other expressions’ express.
In other words, it wouldn’t Backtracking when matches.
1 | *+ |
\b\d++\b
\b(?>\d+)\b
ps. (?>\d+)
is an atomic group that essentially is a noncapturing group,
with the extra job of refusing to backtrack.
\w++\d++
can’t mathes “123abc”
Because \w++
selfishly occupy “123abc”, don’t care \d++ failed to match.
When use (\w+)(\d+)
to match “123abc”, i found gourp \1 matches “12”
and group \2 matches “3”, so greedy works.
It’s not mean selfish is bad, but only unusual work in simply task.
Why prevent? because in some complex condition, expression will complex the same.
In these condition Possessive quantifiers
is necessary.
Match a html’s origin code
Solution1
2<html>(?>.*?<head>)(?>.*?<title>)(?>.*?</title>)↵
(?>.*?</head>)(?>.*?<body[^>]*>)(?>.*?</body>).*?</html>
ps.If some tag properties need be matched, please modify expression.
This regular expression has a worst-case complexity$^3$ of $O(n^7)$
If the file is twice the size, the regex can need up to 128 times
as many steps to figure out it doesn’t match.
(x+x+)+y
to matches “xxxxxxxxxx”
It should not matches, watching the operation progress.
This regex is $O(2^n)$, if one more ‘x’ is added, the regex can need up to 2times
sign
1 | | |
a | b |
---|---|
` | backquote 反引号 |
~ | tilde |
! | exclam |
@ | at |
# | numbersign,英语国家是hash</br>美语是pound</br>音乐里作sharp,如C# |
$ | dollar |
% | percent |
^ | caret |
& | ampersand |
* | asterisk,star(美语),数学公式中作multiply |
( | parenleft,opening parentheses |
) | parenright,closing paretheses |
- | minus;hyphen连字符,不读 |
_ | underscore |
+ | plus |
= | equal |
[ | bracketleft,opening bracket |
] | bracketright,closing bracket |
{ | braceleft |
} | braceright |
; | semicolon |
: | colon |
‘ | quote |
“ | doublequote |
/ | slash |
\ | backslash 反斜杠 |
| | bar |
, | comma |
< | less angle brackets |
> | greater angle brackets |
. | period |
? | question |
space |
\b(\d\d(\d\d))-\2-\2\b
From outer to inner , from left to right number increase start from 1.
\b(?i:Mary|Jane|Sue)\b
(?i-sm:Mary.*?\r\n)
Inner config the group capture options
parentheses start like ‘?:’ ‘?xxx:’, means group match but no capture.
\b\d\d(\d\d)-\1-\1\b
\01 is either an octal escape or an error, dont’t use it.
\xFF hexadecimal escapes are much easier to understandJavaScript if the
\1
appear in front of group it match like a zero-length\d\d\1-\1-(\d\d)
can match12--34
after ‘2’ and ‘-‘ two zero-length position matches.
\b(?<year>\d\d\d\d)-(?<month>\d\d)-(?<day>\d\d)\b
\b(?'year'\d\d\d\d)-(?'month'\d\d)-(?'day'\d\d)\b
\b(?P<year>\d\d\d\d)-(?P<month>\d\d)-(?P<day>\d\d)\b
\b\d\d(?<magic>\d\d)-\k<magic>-\k<magic>\b
\b\d\d(?'magic'\d\d)-\k'magic'-\k'magic'\b
\b\d\d(?P<magic>\d\d)-(?P=magic)-(?P=magic)\b
Group’s name must consist of word characters matched by \w
Angle brackets not friend in xml style environment.
So some language support use in '
single quotes instead of angle brackets.
Use same name in expression is not recommanded
Python was the first regular expression flavor to support named capture.
Perhaps due to .NET’s popularity over Python, the .NET syntax seems to be the one
that other regex library developers prefer to copy. Perl 5.10
and later have it, and so
does the Oniguruma engine in Ruby 1.9
. Perl 5.10
and Ruby 1.9
support both the syntax
using angle brackets and single quotes. Java 7 also copied the .NET syntax
, but only
the variant using angle brackets. Standard JavaScript does not support named capture.
XRegExp adds support for named capture using the .NET syntax, but only the variant
with angle brackets.
PCRE copied Python’s syntax long ago, at a time when Perl did not support named
capture at all. PCRE 7
, the version that adds the new features in Perl 5.10
, supports
both the .NET syntax and the Python syntax. Perhaps as a testament to the success of
PCRE, in a reverse compatibility move, Perl 5.10
also supports the Python syntax. In
PCRE and Perl 5.10, the functionality of the .NET syntax and the Python syntax for
named capture is identical.
Interesting! a lot of fun
Bug in 2017-02-02
Raspberry Pi -Read 20Mb/s Write 20Mb/s in board tf card
1 | sudo nano /etc/default/keyboard |
1 | sudo raspi-config |
1 | sudo nano /etc/wpa_supplicant/wpa_supplicant.conf |
if not work first check ssid & passwd correct
then ckeck net card status1
2iwconfig
ifconfig wlan0
try manually restart the interface withsudo ifdown wlan0
and sudo ifup wlan0
at last try sudo reboot
Version | Description |
---|---|
JavaScript 1.0 | The original version of the language. It was buggy and is now essentially obsolete. Implemented by Netscape 2. |
JavaScript 1.1 | Introduced a true Array object; most serious bugs resolved. Implemented by Netscape 3. |
JavaScript 1.2 | Introduced the switch statement, regular expressions, and a number of other features. Almost compliant with ECMA v1, but has some incompatibilities. Implemented by Netscape 4. |
JavaScript 1.3 | Fixed incompatibilities of JavaScript 1.2. Compliant with ECMA v1. Implemented by Netscape 4.5. |
JavaScript 1.4 | Implemented only in Netscape server products. |
JavaScript 1.5 | Introduced exception handling. Compliant with ECMA v3. Implemented by Mozilla and Netscape 6. |
JScript 1.0 | Roughly equivalent to JavaScript 1.0. Implemented by early releases of IE 3. |
JScript 2.0 | Roughly equivalent to JavaScript 1.1. Implemented by later releases of IE 3. |
JScript 3.0 | Roughly equivalent to JavaScript 1.3. Compliant with ECMA v1. Implemented by IE 4. |
JScript 4.0 | Not implemented by any web browser. |
JScript 5.0 | Supported exception handling. Partially compliant with ECMA v3. Implemented by IE 5. |
JScript 5.5 | Roughly equivalent to JavaScript 1.5. Fully compliant with ECMA v3. Implemented by IE 5.5 and IE 6. (IE 6 actually implements JScript 5.6, but 5.6 is not different from 5.5 in any way that is relevant to client-side JavaScript programmers.) |
ECMA v1 | The first standard version of the language. Standardized the basic features of JavaScript 1.1 and added a few new features. Did not standardize the switch statement or regular expression support. Conformant implementations are JavaScript 1.3 and JScript 3.0. |
ECMA v2 | A maintenance release of the standard that included clarifications but defined no new features. |
ECMA v3 | Standardized the switch statement, regular expressions, and exception handling. Conformant implementations are JavaScript 1.5 and JScript 5.5. |