TOP Language sed Regular Expression Table



PCRE

Perl Compatible Regular Expressions
PCRE

Examples

match

#include <regex.h>
//LOPT+= -lc
regex_t preg;
if (regcomp(&preg,RegexStr,REG_EXTENDED|REG_NOSUB|REG_NEWLINE) != 0) {
    regfree(&preg);
    throw regex_compile_failed;
}
if (regexec(&preg, line, 0, NULL, 0) != REG_NOMATCH) {
    Found=true;
}
regfree(&preg);

C++/CLR

Regex^=gcnew Regex(reg);
Match^ m=r->Match(input);
String^ g = m->Success?m->Groups[1]:"";
reginputg
<[Bb]>([あ-んア-ン]+)</[Bb]><B>ひらがな</B>ひらがな

memo

(?=...)肯定先読み
(?<=...)肯定戻り読み
(?!...)否定先読み
(?<!...)否定戻り読み

量指定子

?0または1
*0以上
+1以上

繰り返し

A{3,5}Aが3以上5以下繰り返し

NOT

[^ABC]AでもBでもCでもない文字

cflag (regcomp 3rd param)

REG_EXTENDEDextended
REG_BASIC= 0
REG_NOSPECno special char, This can't use with extened
REG_ICASEignore case
REG_NOSUBno substitute? -> no buffer required
REG_NEWLINEdetect new line in the string
REG_PENDallow 0(null) in the regex

Error Code

error codes from regcomp(),regexec()|
0no error
REG_NOMATCHregexec() failed to match
REG_BADPATinvalid regular expression
REG_ECOLLATEinvalid collate
REG_ECTYPEinvalid character class
REG_EESCAPE'\' is used for in-adequate char
REG_ESUBREGinvalid back reference number
REG_EBRACK`[ ]' mis-match
REG_EPAREN`( )' mis-match
REG_EBRACE`{ }' mis-match
REG_BADBR{ }' invalid repeat number
REG_ERANGE[ ]' invalid char range
REG_ESPACElack of memory
REG_BADRPT?', `*' or `+' operands are invalid
REG_EMPTYempty
REG_ASSERTBUG!
REG_INVARGinvalid parameter
REG_ILLSEQinvalid byte sequence

regmatch_t

typedef struct 
{ 
    regoff_t rm_so ; 
    regoff_t rm_eo ; 
} regmatch_t; 

Sample

regexSourceresult
sh.*matchshortest match longest matchshortest match longest match
sh.*?matchshortest match longest matchshortest match
s/(?<=\d)(?=(\d{3,3})+(?!\d))/,/g12345671,234,567

vim

s/pattern/&/matches the entire previously matched pattern
s/\(pattern\)/\1/matches the first captured pattern
\{-}quantifier to match the shortest, instead of longest (greedy), version of the pattern
:%s/<.\{-}>//gmatches (and removes) all HTML tags
a[bc]\{-}[cd]matches "abc" in "abcd"
a[bc]*[cd]matches "abcd" in "abcd"

comparison

namePerlPCRE.NETJavaJavaScriptPythonRUby
loc(integrated)libSystem.Text.RegularExpressions.Regexjava.util.regexECMA-262 V3re(integrated)
replaces/regex/replace/N/ARegex.Replace()sub()

tool

Animator

reAnimator .. Online

PCRE

PHP PCRE .. Online
.NET
Nregex ... Online
The Regulator .. Download

JavaScript

RegexPal .. Online

Ruby

Rubular .. Online

Windows

RegexBUddy .. 7 days evaluation. Download.
PowerGrep .. 15 days eva. dl.
Expresso .. .NET2.0 App 60days Eva

管理人/副管理人のみ編集できます