default

Regular expression metacharacters

Metacharacters are the building blocks of regular expressions. Characters in RegEx are understood to be either a metacharacter with a special meaning or a regular character with a literal meaning.

The following are some common RegEx metacharacters and examples of what they would match or not match in RegEx.

Metacharacter Description Examples
\d Whole Number 0 – 9

\d\d\d = 327

\d\d = 81

\d = 4

—————————————–

\d\d\d ≠  24631

\d\d\d doesn’t return 24631 because 24631 contains 5 digits.  \d\d\d only matches for a 3-digit string.

 

\w Alphanumeric Character

\w\w\w = dog

\w\w\w\w = mule

\w\w = to

—————————————–

\w\w\w = 467

\w\w\w\w = 4673

—————————————–

\w\w\w ≠  boat

\w\w\w doesn’t return boat because boat contains 4 characters.

—————————————–

\w ≠  !

\w doesn’t return the exclamation point ! because it is a non-alphanumeric character.

 

\W Symbols

\W = %

\W = #

\W\W\W = @#%

—————————————–

\W\W\W\W ≠  dog8

\W\W\W\W doesn’t return dog8 because d, o, g, and 8 are alphanumeric characters.

 

[a-z]

[0-9]

Character set, at least one of which must be a match, but no more than one unless otherwise specified.

The order of the characters does not matter.

pand[ora] = panda

pand[ora] = pando

—————————————–

pand[ora] ≠  pandora

pand[ora] doesn’t bring back pandora because it is implied in pand[ora] that only 1 character in [ora] can return.

 

(Quantifiers that allow pand[ora] to match for pandora is discussed below.)

 

(abc)

(123)

Character group, matches the characters abc or 123 in that exact order.

pand(ora) = pandora

pand(123) = pand123

—————————————–

pand(oar) ≠  pandora

pand(oar) does not match for pandora because it’s looking for the exact phrase pandoar.

 

| Alternation – allows for alternate matches. | operates like the Boolean OR. pand(abc|123) = pandora OR pand123
? Question mark matches when the character preceding ? occurs 0 or 1 time only, making the character match optional.

colou?r = colour (u is found 1 time)

colou?r = color (u is found 0 times)

 

*

Asterisk matches when the character preceding * matches 0 or more times.

 

Note: * in RegEx is different from * in dtSearch.  RegEx * is asking to find where the character (or grouping) preceding * is found ZERO or more times.  dtSearch * is asking to find where the string of characters preceding * or following * is found 1 or more times.

tre*= tree (e is found 2 times)

tre* = tre (e is found 1 time)

tre* = tr (e is found 0 times)

—————————————–

tre* ≠  trees

tre* doesn’t match the term trees because although “e” is found 2 times, it is followed by “s”, which is not accounted for in the RegEx.

+ Plus sign matches when the character preceding + matches 1 or more times. The + sign makes the character match mandatory.

tre+ = tree (e is found 2 times)

tre+ = tre (e is found 1 time)

—————————————–

tre+ ≠  tr (e is found 0 times)

tre+ doesn’t match for tr because e is found zero times in tr.

 

. (period) The period matches any alphanumeric character or symbol.

ton. = tone

ton. = ton#

ton. = ton4

—————————————–

ton. ≠  tones

ton. doesn’t match for the term tones because . by itself will only match for a single character, here, in the 4th position of the term.  In tones, s is the 5th character and is not accounted for in the RegEx.

.*

 

 

Combine the metacharacters . and *, in that order .* to match for any character 0 or more times.

 

NOTE:  .* in RegEx is equivalent to dtSearch wildcard * operator.

 

 

tr.* = tr

tr.* = tre

tr.* = tree

tr.* = trees

tr.* = trough

tr.* = treadmill

 

RegEx quantifiers

RegEx use quantifiers to indicate the scope of a search string. You can use multiple quantifiers in your search string. The following table gives examples of the quantifiers you can use in your RegEx:

Quantifier Description Examples
{n} Matches when the preceding character, or character group, occurs n times exactly.

\d{3} = 836

\d{3} = 139

\d{3} = 532

—————————————–

pand[ora]{2} = pandar

pand[ora]{2} = pandoo

pand(ora){2} = pandoraora

—————————————–

pand[ora]{2} ≠  pandora

pand[ora]{2} doesn’t match for pandora because the quantifier {2} only allows for 2 letters from the character set [ora].

 

{n,m} Matches when the preceding character, or character group, occurs at least n times, and at most m times.

\d{2,5} = 97430

\d{2,5} = 9743

\d{2,5} = 97

—————————————–

\d{2,5} ≠  9

9 does not match because it is 1 digit, thus outside of the character range.

 

Escaping RegEx Metacharacters

When using RegEx to search for a character that is a reserved metacharacter, use the backslash \ to escape the character so it can be recognized. The following table gives an example on how to escape a reserved metacharacter when searching.

Search For RegEx Match Results

UK phone number

 

\+[0-9]{11}

+14528280001

+38119930978

—————————————–

If the + sign is not escaped with a backslash, RegEx treats + as a quantifier instead of the literal plus sign character.

 

default

a basic git tutorial

DVCS (such as Git, Mercurial, Bazaar or Darcs)

Git was written by Linus Torvalds on the first version,He described the tool as “the stupid content tracker”,So don’t be afraid of Git.

It is a good idea to introduce yourself to Git with your name and
public email address before doing any operation. The easiest
way to do so is:

$ git config --global user.name "Your Name Comes Here"
$ git config --global user.email you@yourdomain.example.com

Initialized empty Git repository in .git/

git init

 

git add .

Git tracks content not files
—————————-

Many revision control systems provide an `add` command that tells the
system to start tracking changes to a new file. Git’s `add` command
does something simpler and more powerful: ‘git add’ is used both for new
and newly modified files, and in both cases it takes a snapshot of the
given files and stages that content in the index, ready for inclusion in
the next commit.

This snapshot is now stored in a temporary staging area which Git calls
the “index”. You can permanently store the contents of the index in the
repository with ‘git commit’:

 

git commit

A note on commit messages: Though not required, it’s a good idea to
begin the commit message with a single short (less than 50 character)
line summarizing the change, followed by a blank line and then a more
thorough description. The text up to the first blank line in a commit
message is treated as the commit title, and that title is used
throughout Git. For example, linkgit:git-format-patch[1] turns a
commit into email, and it uses the title on the Subject line and the
rest of the commit in the body.

 git commit -a

which will automatically notice any modified (but not new) files, add
them to the index, and commit, all in one step.

git add file1 file2 file3

You are now ready to commit. You can see what is about to be committed
using ‘git diff’ with the –cached option:

git diff --cached

 

$ git status

 

git log

If you also want to see complete diffs at each step, use

git log -p

 

git branch

 

git checkout 'your_branch'

 

git merge 'some one branch'

If the changes don’t conflict, you’re done. If there are conflicts,
markers will be left in the problematic files showing the conflict;

git diff

will show a nice graphical representation of the resulting history.

gitk

At this point you could delete the experimental branch with

git branch -d 'your_branch'

 

git clone /home/alice/project myrepo

The “pull” command thus performs two operations: it fetches changes
from a remote branch, then merges them into the current branch

local changes committed before
initiating this “pull”.

git pull /home/bob/myrepo master
git fetch /home/bob/myrepo master
git log -p HEAD..FETCH_HEAD
gitk HEAD..FETCH_HEAD
git difftool
git difftool --tool-help
git rm
git rm --cached
git commit --amend

 

git checkout -- <file>
git remote add pb https://github.com/paulboone/ticgit
 git push [remote-name] [branch-name]
git remote show [remote-name]
git remote rename
git remote rm paul
git tag
git checkout -b version2 v2.0.0

permanently delete remote ref

git push --delete rep ref
git push rep :ref
eg..git push --delete origin dev  is equivalent to git push origin :dev

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

default

xdebug config

zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/xdebug.so;
xdebug.auto_trace=1;
xdebug.collect_assignments=1;
xdebug.collect_params=1;
xdebug.collect_return=1;
xdebug.remote_enable=1;
xdebug.remote_host=192.168.3.103;
xdebug.remote_port=9000;
xdebug.idekey=phpstorm;
xdebug.collect_vars=1;
;xdebug.profiler_aggregate=1;
;xdebug.profiler_append=1;
;xdebug.profiler_enable=1;
;xdebug.profiler_enable_trigger=1;
;xdebug.show_error_trace=1;
;xdebug.show_exception_trace=1;
xdebug.show_local_vars=1;
xdebug.remote_autostart=1;
;xdebug.trace_enable_trigger=1;

default

remove index.php from the URL when uses the CI framework(nginx)

  Apache is great(if you need help about Apache configuration you can see here),but Nginx ( pronounce “engine X”) maybe more powerful in high performance.So I write this paper for someone work with Nginx and php-fpm.

If it haven’t been installed,you can see here,

  • Open your configuration file in directory  /etc/nginx/conf.d/xxx.conf , add blow in your configuration file.
    location / { 
    try_files $uri $uri/ /index.php;
    }

    Now we will explain what is the meaning,First “location /” is a directive location plus URI “/” that means if your URI just like this “http://www.example.com/” or “http://www.example.com”.this role will take effect.Secondly,try_files directive will try to find the $url file.if not existence,then to find $url/.if both all not existence.”/index.php” file will be used as default file to run.So we can remove index.php from the URL.
    The configuration filelike this:

  • nginx_1
default

how to change window 10 title bar color

I update my window 7 to window 10 version 10240 feel better,but good day not very long.
I upgraded to win 10 version 10586,It suppose to give me a surprising,but it not,
only make me uncomfortable just like this:title bar looks not very clearly and briefly.


before_change

one day i found a method to change register table that can change the color whether or not change color of task bar.

step1:open your register table,win+r enter regedit

step2:find [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\DWM]

step3:change “ColorPrevalence”=0

note:1 is colorful and 0 is white

after_change

 

if you want to change task bar color,just follow below steps

step1:find [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize]

step2:change ColorPrevalence”=0

note:0 is black and 1 is colorful

good luck to you!

default

php late static bindings lab

小蝙常常被后期静态绑定给迷惑,相信有跟我一样笨的童鞋,今天就来做做实验,看看什么是后期静态绑定。

先看一段代码:

<?php
class A {
 public static function foo(){
 static::who();
 }
 public static function who(){
 echo get_called_class()."\n";
 }
}
class B extends A {
 public static function test(){
 A::foo();
 parent::foo();
 self::foo();
 }
 public static function who(){
 echo get_called_class()."\n";
 }

}
class C extends B {
 public static function who(){
 echo get_called_class()."\n";
 }
}
C::test();

?>

运行结果:

ACC

有没有感觉到意外呢?其实很简单,听我一说你就明白了,要实现后期静态绑定功能,那么php解释器就要知道绑定的类是谁,php会在内部存储一个非转发调用类名,也就是最先调用的类名(也就是这个形式的className::functionName().都会把className给存起来,遇到self::functionName(),或者self::functionName();的不会去存储self或者parent,说白了self和parent都是不清楚的,都是运行时才知道的东西),这个是类名,不能使parent或者self关键字,一旦遇到static::functionname();这种形式的静态调用的时候,就把最先存储的类名(也就是className)拿来用,如果还没有明白的话,那就解释一下上面的例子,首先C调用test()静态方法(C::test();这样的形式符合),如果test()不是静态的,是不能用::符来调用的,会出错,php解析器会记录一项原始调用类名,到了A::foo()时,记录另外一个原始调用类名A,执行foo()方法,遇到static::who()语句,就立刻将static变成原始调用类名A,有人可能要问怎么不是C,这是php解析器遇到”类名::function()”这种形式的都会开辟一块新的地址空间来存,所以第一个echo出来的是A,我们再看parent::foo();语句,前面我们说过php只会存储原始类名,不会存储parent和self关键字,所以在A类里面执行到static::who()方法时,会将之前存储的C原始类名替换static关键字,所以变成了C::who();语句,输出来的就是C,之后执行的self::foo();语句也是一样的情况。这样说了,是不是感觉超简单

default

php constructor lab

php 有几种编写构造函数的方法,第一种是__construct(),第二种是与类名同名的函数,不过据官方的文档说,到了5.3.3之后就不再支持了。As of PHP 5.3.3, methods with the same name as the last element of a namespaced class name will no longer be treated as constructor. This change doesn’t affect non-namespaced classes.

运行如下代码:

<?php
class a {
 public static function a(){
 echo "a";
 }
}
echo "your php version: ".PHP_VERSION;
a::a();
?>

运行结果:

PHP Fatal error:  Constructor a::a() cannot be static

如果加上命名空间那么结果就不一样了

<?php

namespace Foo;
class a {
 public static function a(){
 echo "a";
 }
}
echo "your php version: ".PHP_VERSION;
a::a();
?>

运行结果:

your php version: 5.5.20normal method

代码如下就会出现这种结果:

<?php
class a {
 public function a(){
 echo "normal method";
 }
}
echo "your php version: ".PHP_VERSION;
$c = new a;
?>

运行结果:

your php version: 5.5.20normal method

如果加上命名空间

<?php
namespace Foo;
class a {
 public function a(){
 echo "normal method";
 }
}
echo "your php version: ".PHP_VERSION;
$c = new a;
?>

运行结果就是:

your php version: 5.5.20(没有报错)

总结一下:如果一个类加了命名空间,那么与类同名的函数就不会作为构造函数使用,如果没有加上命名空间,那么与类同名的函数就会被当做构造函数使用,小蝙之前不知道,被害苦死了,牺牲小蝙一人,分享一下这痛苦的经验,