如何用正则表达式提取字符串。 (20分)

  • 主题发起人 主题发起人 ligumaloes
  • 开始时间 开始时间
L

ligumaloes

Unregistered / Unconfirmed
GUEST, unregistred user!
如何用正则表达式提取以下字符串(Subject: XXXXX 换行)中的XXXXX表未知字符串。
用/^(Subject:[/t].*/n)/mi错在哪里?如果有关正则表达式的语法请E-Mail一份给我。
magiciori@sina.com 。谢谢!
 
何为正则表达式我都忘了,你能给我说明吗
 
Regular Expressions:

Symbol Function
/ Marks the next character as a special character. "n" matches the character "n". "/n" matches a linefeed or newline character.
^ Matches/anchors the beginning of line.
$ Matches/anchors the end of line.
* Matches the preceding character zero or more times.
+ Matches the preceding character one or more times.
. Matches any single character except a newline character.
(expression) Brackets or tags an expression to use in the replace command.A regular expression may have up to 9 tagged expressions, numbered according to their order in the regular expression.The corresponding replacement expression is /x, for x in the range 1-9. Example: If (h.*o) (f.*s) matches "hello folks", /2 /1 would replace it with "folks hello".
[xyz] A character set. Matches any characters between brackets.
[^xyz] A negative character set. Matches any characters NOT between brackets.
/d Matches a digit character. Equivalent to [0-9].
/D Matches a nondigit character. Equivalent to [^0-9].
/f Matches a form-feed character.
/n Matches a linefeed character.
/r Matches a carriage return character.
/s Matches any white space including space, tab, form-feed, etc but not newline.
/S Matches any nonwhite space character but not newline.
/t Matches a tab character.
/v Matches a vertical tab character.
/w Matches any word character including underscore.
/W Matches any nonword character.
Note - ^ refers to the character '^' NOT Control Key + value.

Examples:

m.n matches "man", "men", "min" but not "moon".

Te+st matches "test", "teest", "teeeest" etc. BUT NOT "tst".

Te*st matches "test", "teest", "teeeest" etc. AND "tst".

[aeiou] matches every lowercase vowel
[,.?] matches a literal ",", "." or "?".
[0-9, a-z] matches any digit, or lowercase letter
[^0-9] matches any character except a digit (^ means NOT the following)

You may search for an expression A or B as follow:

"(John|Tom)"

This will search for an occurrence of John or Tom. There should be nothing between the two expressions.

You may combine A or B and C or D in the same search as follows:

"(John|Tom)(Smith|Jones)"


This will search for John or Tom followed by Smith or Jones.

Additionally:

/p Matches CR/LF (same as /r/n) to match a DOS line terminator

If Regular Expression is not selected for the find/replace and in the Replace field the following special characters are also valid:

Symbol Function
^^ Matches a "^" character
^s Is substituted with the selected (highlighted) text of the active file window.
^c Is substituted with the contents of the clipboard.
^b Matches a page break
^p Matches a newline (CR/LF) (paragraph) (DOS Files)
^r Matches a newline (CR Only) (paragraph) (MAC Files)
^n Matches a newline (LF Only) (paragraph) (UNIX Files)
^t Matches a tab character

Note - ^ refers to the character '^' NOT Control Key + value.
 
唉,不能订邮件了,只能手工订了:(
 
主要问题在表达式/^(Subject:[/t].*/n)/mi有没有错?
 
/^(Subject:[/s].*/n)/mi
这样?
 
to:ahxia
是一个多行文本中有一行是
Subject: XXXXX
其中XXXXX表未知字符串。
取出XXXXX。
 
试试这个? /Subject:[/s]*(.*)/n/gi
 
还是没通过,我用的正则表达式控件是这个。TRegExpr in English, Russian, German
and Bulgarian available at my home page
http://anso.da.ru/ or http://anso.virtualave.net/
可能与Perl的有点不同。虽然分很少,但这么久的问题还有人答,就把分送出。下次再
多给点吧。
 

Similar threads

后退
顶部