Posts Tagged 'regular'

Expressions Collection

January 24th, 2009

Regular expressions are a variety of different styles. The following table is a Ghost in the PCRE regular expression characters and their behavior in the context of a complete list:

Character Description
\ Will be the next character is marked as a special character, or a literal character, or a backward reference, or an octal escape. For example, "n" matches the character "n". "\ N" matches a newline character. Sequence "\ \" matches "\" and "\ (" the match "(."
^ Match the input string starting position. If you set the RegExp object's Multiline property, ^ also matches the "\ n" or "\ r" after the location.
$ Enter the string matching the end position. If you set the RegExp object's Multiline property, $ also matches the "\ n" or "\ r" before the position.
* Match the preceding subexpression zero or more times. For example, zo * to match the "z" and "zoo". * Is equivalent to (0).
+ Match the preceding subexpression one or more times. For example, "zo +" to match "zo" and "zoo", but can not match the "z". + Is equivalent to (1,).
? Match the preceding subexpression zero or one. For example, "do (es)?" Matches "do" or "does" in the "do". ? Is equivalent to (0,1).
(N) n is a non-negative integers. Matching of the n times. For example, "o (2)" can not match the "Bob" in the "o", but can match the "food" in the two o.
(N,) n is a non-negative integers. Match at least n times. For example, "o (2,)" can not match the "Bob" in the "o", but it can match "foooood" all of the o. "O (1,)" is equivalent to "o +". "O (0,)" is equivalent to "o *".
} (N, m) 均为非负整数,其中n <= m m and n are non-negative integers, where n <= m. 次。 Match at least n times and match up to m times. For example, "o (1,3)" will match "fooooood" in the first three o. "O (0,1)" is equivalent to "o?". Please note that the comma and no space between the two numbers.
? ,},{ n , m })后面时,匹配模式是非贪婪的。 When the characters followed in any other qualifier (*,+,?,{ n), (n,), (n, m)) back when the non-greedy matching pattern. Non-greedy pattern matches as little as possible the search string, and the default greedy pattern matches as much as possible the search string. For example, the string "oooo", "o +?" Will match a single "o", and "o +" will match all the "o".
. Match except "\ n" beyond any single character. ]”的模式。 To match including "\ n", including any characters, please use something like "[. \ N]" of the model.
(Pattern) Match the pattern and get the match. Match can be obtained from the resulting Matches collection are, in VBScript using SubMatches collection in JScript is used in the $ 0 ... $ 9 properties. To match parentheses characters, use "\ (" or "\)."
(?: Pattern) Match the pattern but do not get matching results, that this is a non-access match, not to store for later use. This use of "or" character (|) to combine the various parts of a model is useful. For example, "industr (?: Y | ies) is a ratio of" industry | industries' more simple expressions.
(? = Pattern) Positive pre-investigation, in any matching string pattern matching to find the beginning of the string. This is a non-access match, that is, the match does not need access to for future use. For example, "Windows (? = 95 | 98 | NT | 2000)" can match "Windows2000" in the "Windows", but can not match "Windows3.1" in the "Windows". Pre-check does not consume characters, that is, in a match occurs, the last match in the next match started immediately after the search, rather than from the characters that contains pre-investigation began after.
(?! Pattern) Negative pre-investigation, in any string does not match the pattern matches the beginning of search string. This is a non-access match, that is, the match does not need access to for future use. For example "Windows (?! 95 | 98 | NT | 2000)" can match "Windows3.1" in the "Windows", but can not match "Windows2000" in the "Windows". Pre-check do not consume characters, that is, in a match occurs, the last match in the next match started immediately after the search, not including pre-check of the characters from the beginning after
x | y Match x or y. For example, "z | food" can match the "z" or "food". "(Z | f) ood" the match "zood" or "food".
[Xyz] Character set. Matches any character included. For example, "[abc]" matches "plain" in the "a".
[^ Xyz] Negative character set. Matches any character not included. For example, "[^ abc]" matches "plain" in the "p".
[Az] Character range. Matches any character within the specified range. For example, "[az]" matches "a" to "z" within the scope of any lowercase alphabetic characters.
[^ Az] Range of negative characters. Does not match any arbitrary character within the specified range. For example, "[^ az]" can not match any "a" to "z" within the scope of any character.
\ B Match a word boundary, that is, that space between words and the location. For example, "er \ b" matches "never" in "er", but can not match the "verb" in the "er".
\ B Match non-word boundary. "Er \ B" to match "verb" in the "er", but can not match "never" in "er".
\ Cx Match x specified by the control characters. For example, \ cM matches a Control-M or carriage return. x value must be one of AZ or az. Otherwise, c as a literal "c" character.
\ D Match a digit character. Is equivalent to [0-9].
\ D Match a non-numeric characters. Is equivalent to [^ 0-9].
\ F Match a feed character. Is equivalent to \ x0c and \ cL.
\ N Match a newline. Is equivalent to \ x0a and \ cJ.
\ R Matches a carriage return. Is equivalent to \ x0d and \ cM.
\ S Matches any white space characters, including spaces, tabs, page breaks, etc. change. Is equivalent to [\ f \ n \ r \ t \ v].
\ S Match any non-blank character. Is equivalent to [^ \ f \ n \ r \ t \ v].
\ T Match a tab character. Is equivalent to \ x09 and \ cI.
\ V Matches a vertical tab. Is equivalent to \ x0b and \ cK.
\ W Match any word character including underscore. Is equivalent to "[A-Za-z0-9_]".
\ W Matches any non word character. Is equivalent to "[^ A-Za-z0-9_]".
\ X n 为十六进制转义值。 Match n, where n is a hexadecimal escape value. Hexadecimal escape values must be determined by two numbers long. For example, "\ x41" matches "A". "\ X041" is equivalent to "\ x04" & "1". Regular expressions can be used in ASCII encoding. .
\ Num 是一个正整数。 Match num, where num is a positive integer. Get on the matching references. For example ,"(.) \ 1 "matches two consecutive identical characters.
\ N Identifies an octal escape value or a backward reference. 个获取的子表达式,则n为向后引用。 If the \ n at least n months to obtain prior to the sub-expression, then n to refer back to. 为一个八进制转义值。 Otherwise, if n is an octal digit (0-7), then n is an octal escape value.
\ Nm Identifies an octal escape value or a backward reference. 个获得子表达式,则nm为向后引用。 If \ nm nm were obtained at least before the sub-expression, then nm to refer back to. 个获取,则n为一个后跟文字m的向后引用。 If \ nm at least n months before the acquisition, followed by the text is n m for a backward reference. 均为八进制数字(0-7),则\ nm将匹配八进制转义值nm If the preceding conditions are not met, if n and m are octal digits (0-7), then \ nm matches octal escape value nm.
\ Nml 均为八进制数字(0-7),则匹配八进制转义值nm l。 If n is an octal digit (0-3), and m and l are octal digits (0-7), then match the octal escape value nm l.
\ U n 是一个用四个十六进制数字表示的Unicode字符。 Match n, where n is a hexadecimal digits in four of Unicode characters. For example, \ u00A9 matches the copyright symbol (©).

Popularity: 27%

Apache's Mod_rewrite example

April 19th, 2008

Prevention of GetRight and Curl to grab the data within the network code

RewriteEngine on
RewriteBase /
RewriteCond% (HTTP_USER_AGENT) ^ curl [OR]
RewriteCond% (HTTP_USER_AGENT) ^ GetRight
RewriteRule ^ .* - [F]

»More: Apache's Mod_rewrite example

Popularity: 27%

python non-greedy, multi-line matches the regular expression examples

April 14th, 2008

Some regular's tips:

A non-greedy flag

. findall ( r " a( \d +?) " , " a23b " ) >>> Re. Findall (r "a (\ d +?)", "A23b")
2 ' ] ['2']
. findall ( r " a( \d +) " , " a23b " ) >>> Re. Findall (r "a (\ d +)", "a23b")
23 ' ] ['23']

Note this comparison:

. findall ( r " a( \d +)b " , " a23b " ) >>> Re. Findall (r "a (\ d +) b", "a23b")
23 ' ] ['23']
. findall ( r " a( \d +?)b " , " a23b " ) >>> Re. Findall (r "a (\ d +?) B", "a23b")
23 ' ] ['23']

2 If you want multiple lines match, then the plus sign re.S and re.M
re.S:. will match the newline character, the default. does not match newline

. findall ( r " a( \d +)b.+a( \d +)b " , " a23b \n a34b " ) >>> Re. Findall (r "a (\ d +) b. + a (\ d +) b", "a23b \ n a34b")
[]
. findall ( r " a( \d +)b.+a( \d +)b " , " a23b \n a34b " , re . S ) >>> Re. Findall (r "a (\ d +) b. + a (\ d +) b", "a23b \ n a34b", re. S)
23 ' , ' 34 ' )] [('23', '34')]
>>>

re.M: ^ $ sign will match every line, default ^ and $ will only match the first line

. findall ( r " ^a( \d +)b " , " a23b \n a34b " ) >>> Re. Findall (r "^ a (\ d +) b", "a23b \ n a34b")
23 ' ] ['23']
. findall ( r " ^a( \d +)b " , " a23b \n a34b " , re . M ) >>> Re. Findall (r "^ a (\ d +) b", "a23b \ n a34b", re. M)
23 ' , ' 34 ' ] ['23' '34']

However, if there is no sign ^,

. findall ( r " a( \d +)b " , " a23b \n a23b " ) >>> Re. Findall (r "a (\ d +) b", "a23b \ n a23b")
23 ' , ' 23 ' ] ['23' '23']

Can be seen, there is no need re.M

Popularity: 52%

learning python regular expressions

April 9th, 2008

Source
python's re module

Regular Expressions

Personally, the main use it to do some complex string analysis, extracting the information you want to learn the principles of: enough on the line, when required in-depth

Are summarized as follows:

Regular expression special symbols:

"." Arbitrary character table
"^" Table string start
"$" The end of the table string "*" "+" "?" With the character behind that 0 - more than one - more than 0 or 1
*?, +?,?? Meet the conditions, match as little as possible / / limit the greed of *,+,? match
(M) matches the previous character, repeated m times
(M, n) m to n times, m, n can be omitted

For example 'a. * b', said a start, b the end of any string
a (5) matches a consecutive five

[] Form a series of characters [abcd] form a, b, c, d [^ a] that non-a
| A | B that A or B, AB to any other regular expression | non-greedy matching, if A is not to find B
(...) The role of the brackets can be understood with an example, to extract information

\ D [0-9]
\ D non-\ d
\ S indicated that the null character
\ S non-empty character
\ W [a-zA-Z0-9_]
\ W non-\ w

1: re the number of function

1: compile (pattern, [flags])
According to the regular expression string pattern and an optional regular expression object flags generated

Generate the regular expression object (see 2)

Which flags have the following definition:
I said Ignore case
L to make some special character set, depending on the current environment
M ^ $ multi-line mode to match the beginning of the end in addition to string, but also match the beginning and end of line
S "." Matches, including '\ n', including any character, or else. Does not include '\ n'
U Make \ w, \ W, \ b, \ B, \ d, \ D, \ s and \ S dependent on the Unicode character properties database
X this is mainly that in order to write regular expressions, but also drugs, will overlook the back of the note space and #

Where S commonly used,
Application forms are as follows
import re
re.compile (... ..., re.S)

2: match (pattern, string, [, flags])
To string matching, pattern, compile with the flag behind the sub-return MatchObject objects as parameters (see 3)

3: split (pattern, string [, maxsplit = 0])
Separate the string with a pattern
>>> Re.split ('\ W +', 'Words, words, words.')
['Words', 'words', 'words','']
Brackets '()' special role within the pattern, please check manual

4: findall (pattern, string [, flags])
Commonly used,
From the string to search non-overlapping pattern of expression consistent with, and then return to the list list

5: sub (pattern, repl, string [, count])
repl can be when the string, you can also type function when the repl is a string,
Consistent pattern within the string is the substring, replace with a repl

When the repl is a function of time, each within a string, not overlapping, matching pattern
Sub-string, called repl (substring), and then replace the substring with the return value

>>> Re.sub (r'def \ s + ([a-zA-Z_] [a-zA-Z_0-9] *) \ s * \ (\ s * \): ',
... R'static PyObject * \ npy_ \ 1 (void) \ n (',
... 'Def myfunc ():')
'Static PyObject * \ npy_myfunc (void) \ n ('

>>> Def dashrepl (matchobj):
... If matchobj.group (0) == '-': return ''
... Else: return '-'
>>> Re.sub ('- (1,2)', dashrepl, 'pro - gram-files')
'Pro-gram files'

2: Regular Expression Object (Regular Expression Objects)

Production methods: by re.compile (pattern, [flags]) Back

match (string [, pos [, endpos]]); return string [pos, endpos] match
pattern of MatchObject (see 3)

split (string [, maxsplit = 0])
findall (string [, pos [, endpos]])
sub (repl, string [, count = 0])
These functions and re module of the same, just call the form of a little difference

re. several functions and regular expression object of several functions, function the same, but the same procedure used for these functions if multiple functions, regular expression object of some function more efficient

3: matchobject

By re.match (... ...) and re.compile (... ...). Match return

The object has the following methods and properties:

Method:
group ([group1, ...])
groups ([default])
groupdict ([default])
start ([group])
end ([group])

Note that the best way of several functions, is an example

matchObj = re.compile (r "(? P \ D +) \. (\ D *) ")
m = matchObj.match ('3 .14 sss')
# M = re.match (r "(? P \ D +) \. (\ D *) ", '3 .14 sss')

print m.group ()
print m.group (0)
print m.group (1)
print m.group (2)
print m.group (1,2)

print m.group (0,1,2)
print m.groups ()
print m.groupdict ()

print m.start (2)
print m.string

Output as follows:
3.14
3.14
3
14
('3 ', '14')
('3 .14 ', '3', '14 ')
('3 ', '14')
('Int': '3 ')
2
3.14sss

Therefore, group () and group (0) returns the entire expression string matching another group (i) is the regular expression using the first i-"()" matches enclosed
('3 .14 ', '3', '14 ') Best describe the problem.

Further study, see the manual

Popularity: 52%

php match the regular expression of all Chinese

April 2nd, 2008

All Chinese characters matching the regular expression is / [1 - 龥] / u, php code is as follows.
To save as utf-8 encoding

<? Php
' /[一-龥]/u ' , ' 龥大家好一s々Ⅳ 4 N ぁΨ Ж ㄩā 몸234adsf ' , $matchs ) ; preg_match_all ('/ [1 -龥] / u', '龥 Hello everybody Ⅳ 4 N a s Hibi defend Ψ Ж ㄩ ā 몸 234adsf', $ matchs);
$matchs ) ; print_r ($ matchs);
?>

The results are:

Array
(
[0] => Array
(
[0] => 龥
[1] => large
[2] => home
[3] => good
[4] => 1
)

)

Here is all that does not contain a string matching the regular expression:
^(?!.*? Word) .* $

Popularity: 27%

UltraEdit regular expression can not be the problem

May 10th, 2007

Have a positive P said ultraedit can not be used, and also made a map as follows:
ue-regux

This situation usually occurs the following several cases
1, check the regex pattern recognition configuration shown in Figure:
ultraedit regular expression
And when the search or replace check on the "regular expression"
2, to see if hotfix www.ultraedit.com
3, in the mirror to check your character

Above order in accordance with the probability ranking.

Popularity: 24%

Linux find examples of common usage (transfer)

May 4th, 2007

find path-option [-print] [-exec-ok command] () \;
#-Print to find the file to standard output
#-Exec command () \; - to find the file implementation of the command operation, () and \; between the space
#-Ok and-exec the same, but consult the user before the operation

================================================== ==

-Name filename # Find the file named filename
-Perm # by the Executive authority to find
-User username # by file owner to find
-Group groupname # by group to find
-Mtime-n + n # change the time according to the documents to find the file,-n means the n days, + n means the n days ago
-Atime-n + n # by file access time to check GIN: 0px ">-perm # by the Executive authority to find
-User username # by file owner to find
-Group groupname # by group to find
-Mtime-n + n # change the time according to the documents to find the file,-n means the n days, + n means the n days ago
-Atime-n + n # by file access time to find the file,-n means the n days, + n means the n days ago
-Ctime-n + n # by file creation time to find the file,-n means the n days, + n means the n days ago
-Nogroup # search without valid documents is a group that the file is set in / etc / groups does not exist
-Nouser # search without a valid owner of the file, that file is a master in the / etc / passwd does not exist
-Newer f1! F2 to find files,-n means the n days, + n means the n days ago
-Ctime-n + n # by file creation time to find the file,-n means the n days, + n means the n days ago
-Nogroup # search without valid documents is a group that the file is set in / etc / groups does not exist
-Nouser # search without a valid owner of the file, that file is a master in the / etc / passwd does not exist
-Newer f1! F2 # check changes of time than the f1 f2 new but old documents than
-Type b / d / c / p / l / f # search is a block device, directory, character devices, pipes, symbolic links, regular files
-Size n [c] # check block length n [or n bytes] file
-Depth # to look into the subdirectory in the directory prior to first find the complete
-Fstype # check changes of time than the f1 f2 new but old documents than
-Type b / d / c / p / l / f # search is a block device, directory, character devices, pipes, symbolic links, regular files
-Size n [c] # check block length n [or n bytes] file
-Depth # to look into the subdirectory in the directory prior to first find the complete
-Fstype # check in a certain type of file system files, the file system type will normally be in the / etc / fstab to find
-Mount # search files across the file system mount point is not
-Follow # If you experience a symbolic link file, follow the link on the documents referred to
-Cpio%; # check in a certain type of file system files, the file system type will normally be in the / etc / fstab to find
-Mount # search files across the file system mount point is not
-Follow # If you experience a symbolic link file, follow the link on the documents referred to
-Cpio # of the matching files using cpio command, will they back up to tape device
-Prune # ignore a directory

================================================== ==
$ Find ~-name "*. txt"-print # in $ HOME in the investigation. Txt file and display
$ Find.-Name "*. txt"-print
$ Find.-Name "[AZ] *"-pri26nbsp; # of the matching files using cpio command, will they back up to tape device
-Prune # ignore a directory

================================================== ===
$ Find ~-name "*. txt"-print # in $ HOME in the investigation. Txt file and display
$ Find.-Name "*. txt"-print
$ Find.-Name "[AZ] *"-print # check with a capital letter at the beginning of the file
$ Find / etc-name "host *"-print # check to host at the beginning of the file
$ Find.-Name "[az] [az] [0 - 9] [0 - 9]. Txt"-print # check to the two lower-case letters and two numbers at the beginning of the txt file
$ Find.-Perm 755-print
$ Find.-Perm -007-exec ls-l () \; # check that all users can read and write files with the implementation-perm 777
$ Find.-Type d-print
$ Find.!-Type d-print
$ Find.-Type l-print

$ Find.-Size +1000000 c-print # check the file length is greater than 1Mb
$ Find.-Size 100c-print # check the file length 100c
$ Find.-Size +10-print # check length of more than 10 files of invalid (1 = 512 bytes)

$ Cd /
$ Find etc home apps-depth-print | cpio-ivcdC65536-o / dev/rmt0
$ Find / etc-name "passwd *"-exec grep "cnscn" () \; # see if there cnscn Users
$ Find.-Name "yao *" | xargs file
$ Find.-Name "yao *" | xargs echo ""> / tmp / core.log
$ Find.-Name "yao *" | xargs chmod ow

================================================== ====

find-name april * in the current directory for files beginning with april
find-name april * fprint file in the current directory for files beginning with april, and the results output to file in
find-name ap *-o-name may * or may look to the beginning of the paper ap
find / mnt-name tom.txt-ftype vfat in / mnt look under the name of tom.txt and file system type vfat file
find / mnt-name t.txt!-ftype vfat in / mnt look under the name of the file system type for the tom.txt and not vfat file
find / tmp-name wa *-type l in / tmp called wa at the beginning of the next search and type symbolic link file
find / home-mtime -2 in / home within the past two days under investigation changed files
find / home-atime -1 check within 1 day files were accessed
find / home-mmin +60 in / home 60 minutes before the next check changed files
find / home-amin +30 30 minutes ago by Charles recently accessed files
find / home-newer tmp.txt in / home longer than tmp.txt under investigation update the file or directory in recent
find / home-anewer tmp.txt in / home access time than tmp.txt under investigation near the file or directory
find / home-used -2 lists the file or directory was changed after 2 days of being accessed in the file or directory
find / home-user cnscn list / home directory is the user cnscn file or directory
find / home-uid +501 list / home directory within the user ID greater than 501 files or directories
find / home-group cnscn list / home cnscn within the group of files or directories
find / home-gid 501 list / home within the group id for the file or directory 501
find / home-nouser list / home does not belong within the local user's files or directories
find / home-nogroup list / home does not belong to local groups within the file or directory
find / home-name tmp.txt-maxdepth 4 out / home when the tmp.txt search depth of up to 3 layers
find / home-name tmp.txt-mindepth 3 from layer 2 start search
find / home-empty find the size of the file or empty directory 0
find / home-size +512 k investigation files larger than 512k
find / home-size-512k 512k less than the paper check
find / home-links +2 check number greater than 2 hard-wired file or directory
find / home-perm 0700 check permissions for the file or directory 700
find / tmp-name tmp.txt-exec cat () \;
find / tmp-name tmp.txt-ok rm () \;

find /-amin -10 # find the last 10 minutes in the system to access the file
find /-atime -2 # Look in the system to access the files the last 48 hours
find /-empty # find empty in the system file or folder
find /-group cat # Look in the system files are groupcat
find /-mmin -5 # Look in the system the last 5 minutes changed files
find /-mtime -1 # find in the system the last 24 hours changed files
find /-nouser # Find the user in the system file is invalid
find /-user fred # search in the system belongs to the user's file FRED

Check the current directory to all common file
---------------------------

# Find.-Type f-exec ls-l () \;
-Rw-r-r-1 root root 34928 2003-02-25. / Conf / httpd.conf
-Rw-r-r-1 root root 12959 2003-02-25. / Conf / magic
-Rw-r-r-1 root root 180 2003-02-25. / Conf.d / README
Check the current directory of all common files, and - exec option to use ls-l command will list them

=================================================
In the / logs directory to find the time to change before the 5 files and delete them:
$ Find logs-type f-mtime +5-exec-ok rm () \;

=================================================
Check that day changed files
[Root @ book class] # find. /-Mtime -1-type f-exec ls-l () \;

=================================================
Check the file and asked to show
[Root @ book class] # find. /-Mtime -1-type f-ok ls-l () \;
<Ls .... / ClassDB.inc.php>? Y
-Rw-r-r-1 cnscn cnscn 13709 1 月 12 12:22. / ClassDB.inc.php
[Root @ book class] # find. /-Mtime -1-type f-ok ls-l () \;
<Ls .... / ClassDB.inc.php>? N
[Root @ book class] #

=================================================
To deal with inquiries and to awk
[Root @ book class] # who | awk '(print $ 1 "\ t" $ 2)'
cnscn pts / 0

=================================================
awk-grep-sed

[Root @ book class] # df-k | awk '(print $ 1)' | grep-v 'none' | sed s "/ \ / dev \ / / / g"
File System
sda2
sda1
[Root @ book class] # df-k | awk '(print $ 1)' | grep-v 'none'
File System
/ Dev/sda2
/ Dev/sda1

1) in / tmp to find all the *. h, and in these documents to find "SYSCALL_VECTOR", the final print out all contain "SYSCALL_VECTOR" file name

A) find / tmp-name "*. h" | xargs-n50 grep SYSCALL_VECTOR
B) grep SYSCALL_VECTOR / tmp / *. h | cut-d ':'-f1 | uniq> filename
C) find / tmp-name "*. h"-exec grep "SYSCALL_VECTOR" () \;-print

2) find /-name filename-exec rm-rf () \;
find /-name filename-ok rm-rf () \;

3) For example to find the disk is larger than 3M in file:
find.-size +3000 k-exec ls-ld ();

4) find out copying it into another place
find *. c-exec cp '()' / tmp ';'

If there is a special file, you can use cpio, you can use this syntax:
find dir-name filename-print | cpio-pdv newdir

6) Look 2004-11-30 16:36:37 When the paper changed
# A = `find. /-Name" * php "` | ls-l-full-time $ A 2> / dev / null | grep "2004-11-30 16:36:37"

Popularity: 24%

UltraEdit Getting Started (1)

March 30th, 2007

The software used for a long time. Written procedures are gradually getting better with it. The process used, summed up some of their tips, the work can improve efficiency. Must have many friends with this software, if there are other good tips, please share them. I tried to make a simple point of use, because the complex I will not. Began throwing bricks.

ctrl + b
Written procedures, brackets correspond generally, but if too many nested, Kan Huayan, how do? You place the cursor on the brackets begin by ctrl + b, UE will help you find the corresponding brackets at the end of the place. You can also try running on a few more press ctrl + b.
»More: UltraEdit Getting Started (1)

Popularity: 32%

ultraedit replace the one case of a regular expression

March 16th, 2007

ultraedit style regular expressions

Search

  1. % 1 $ 1 ^(*^)

Replace

  1. ^ 1

Original content

  1. 1xxxxxx1
  2. 1xxxx1
  3. 1xxzhoxxx1
  4. 1xxz Chinese oxxx1
  5. 1xxxxxx1
  6. 1xxxx1
  7. 1xxzhoxxx1
  8. 1xxz Chinese oxxx1

Result

  1. xxxxxx
  2. xxxx
  3. xxzhoxxx
  4. xxz Chinese oxxx
  5. xxxxxx
  6. xxxx
  7. xxzhoxxx
  8. xxz Chinese oxxx

Popularity: 26%

Grep Tutorial (reposted elsewhere)

February 25th, 2007
1. Grep Introduction
2. Grep regular expression meta-character set (basic set)
3. For egrep and grep-E meta-character extension set
4. POSIX character classes
5. Grep command options
6. Examples

1. Grep Introduction

grep (global search regular expression (RE) and print out the line, fully search for a regular expression and print out the line) is a powerful text search tool, it can use regular expressions to search text, and to match the line of print out. Unix's grep family, including grep, egrep and fgrep. egrep and fgrep grep command with only a very small difference. grep egrep is extended to support more re metacharacters, fgrep is fixed grep or fast grep, they put all the letters as words, that is, the regular expression meta-characters that return to the literal meaning of its own no longer special. linux using the GNU version of grep. It is more powerful, can by-G,-E,-F command line option to use egrep and fgrep functionality.

grep works like this, it is one or more files to search for the string template. If the template includes spaces, you must be a reference template of all the strings are seen as the file name. Search results are sent to the screen, without affecting the original file contents.

grep can be used in shell scripts, because grep by returning a status value to illustrate the search for the state, if the template search is successful, it returns 0, if the search is unsuccessful, it returns 1, if the search of the file does not exist, then return to 2. We can use the return value of some automated text processing.
»More: Grep Tutorial (reposted elsewhere)

Popularity: 23%