text
stringlengths 1
254
| output
stringlengths 2
255
|
---|---|
You can now finally access object member variables and elements from multidimensional arrays within strings.
|
PHP 4ã§ã¯æååäžã®æ°ãã倿°çœ®æã®æ©æ§ã远å ãããŠããŸããæå åäžã®å€æ¬¡å
é
åãããªããžã§ã¯ãã®ã¡ã³ã倿°ãšèŠçŽ ã«ã¢ã¯ã»ã¹ãå¯èœ ãšãªã£ãŠããŸãã
|
To do so you have to enclose your variables with curly braces with the dollar sign immediately following the opening brace: {$...}
|
ãããè¡ãã«ã¯ãéãæ¬åŒ§ã®çŽåŸã«ãã«èšå·ãä»ãããã«å€æ°ãæ³¢æ¬åŒ§ã§ æ¬ãå¿
èŠããããŸãã {$...}
|
This should lead to more readable code, while it may break existing scripts written for PHP 3.
|
ãªããžã§ã¯ãã®ã¡ã³ã倿°ã®å€ãæååã«åã蟌ãã«ã¯ã "text {$obj- member} text" ãšããŸããäžæ¹ãPHP 3 ã§ã¯ã "text ".$obj- member." text" ã®ã ãã«ããå¿
èŠããããŸããã
|
Prev
|
ããã«ããã³ãŒãã®å¯èªæ§ãé«ãŸããŸãããPHP 3çšã«æãããæ¢åã® ã¹ã¯ãªããã¯åäœããªããªãå¯èœæ§ããããŸããããããã³ãŒãäžã® {$ãšããæåã®çµã¿åããã調ã¹ãããšã«ãã容æ ã«ãã®çš®ã®åé¡ã®ç¢ºèªãå¯èœã§ãä»»æã®æ€çŽ¢/眮æããŒã«ã«ãã \{$ ã«çœ®æããããšã«ãã察åŠå¯èœã§ãã
|
Read more on this subject in the global references section.
|
äŸ B-1ã°ããŒãã«å€æ°ã®ç§»è¡
|
This means that in an expression like (1 _BAR_ _BAR_ test_me()), the function test_me() would not be executed since nothing can change the result of the expression after the 1.
|
PHP 3.0 ã«ãããããŒã«è©äŸ¡ã¯ç絡çã§ãããšããã®ã¯ã (1 _BAR__BAR_ test_me()) ã®ãããªè©äŸ¡åŒããããšãããšã颿° test_me() ã¯å®è¡ãããªããšããããšã§ããããã¯ã 1 ãè©äŸ¡ããåŸã¯ãæçµçãªè©äŸ¡çµæãå€ããããšã¯ ã§ããªããšåãã£ãŠããããã§ãã
|
Prev
|
ããã¯äºææ§ã®åé¡ãšããŠã¯äºçްãªããšãããããŸããããæãã¬å¯äœçš ããããããããŸããã
|
You will be supplied with a file name and a line number for the error, though.
|
PHP 3.0 ã®ãšã©ãŒã¡ãã»ãŒãžã¯ã2.0 ãããéåžžã®å Žåæ£ç¢ºã«ãªããŸããã ãããããã¯ããœãŒã¹ã³ãŒãã®ãã¡ãšã©ãŒåå ãšãªã£ãéšåã¯è¡šç€ºãããŸããã ãã®ãããããšã©ãŒã®åå ãšãªã£ããã¡ã€ã«åãšè¡çªå·ã衚瀺ãããã®ã§ã é©ããããããŸããã
|
PHP 3.0 takes both sides into account when determining result types, and this may cause 2.0 scripts to behave unexpectedly in 3.0.
|
PHP/FI 2.0 ã§ã¯ãçµæã®åãæ±ºããã®ã«å·ŠèŸºåŒã䜿ã£ãŠããŸããã PHP 3.0 ã§ã¯ãçµæã®åãæ±ºããã®ã«äž¡èŸºã䜿ãããã«ãªã£ãã®ã§ã 3.0 ç°å¢ã®å
ã§ 2.0 ã®ã¹ã¯ãªãããå®è¡ãããšãäºæããªãçµæã«ãªã å ŽåããããŸãã
|
The fix for this is simple.
|
以äžã®äŸãèããŠã¿ãŸãããã
|
while ((string)$key != "") {
|
ããã解決ããã®ã¯ç°¡åã§ããwhile ã¹ããŒãã¡ã³ãã以äžã®ããã«å€æŽ ããŸãã
|
In addition, PHP' s developers have tried to clean up both PHP's syntax and semantics in version 3.0, and this has also caused some incompatibilities.
|
PHP 3.0 㯠1 ããæžãçŽãããŸãããããã«ã¯ 2.0 ã®ããŒãµã«æ¯ã¹ãŠ ããå
ç¢ã§äžè²«æ§ã®ããé©åãªããŒãµãå
èµãããŠããŸãã3.0 ã¯ãŸãã åçã«éããªããã¡ã¢ãªæ¶è²»éãå°ãªããªã£ãŠããŸããããããªããã ãããã®æ¹åäºé
ã®ãã¡ã®ããã€ãã¯ãæžåŒãšæ©èœã®äž¡é¢ã«ãããŠ äºææ§ãæ¬ ãã倿Žã«ãªã£ãŠããŸã£ãŠããŸãã
|
This chapter will try to guide you through the incompatibilities you might run into when going from PHP / FI 2.0 to PHP 3.0 and help you resolve them.
|
å ããŠãPHP ã®éçºè
ã¯ãPHP 3.0 ã«ãããæžåŒãšæå³ã®åæ¹ããããã« ãçŽãããšããŸãããããããäºææ§ãæ¬ ãèŠå ãšãªã£ãŠããŸããé·ãç® ã§èŠãã°ããããã®å€æŽã¯ããè¯ããã®ã§ãããšç§ãã¡ã¯ä¿¡ããŠããŸãã
|
A conversion program that can automatically convert your old PHP / FI 2.0 scripts exists.
|
ãã®ç« ã§ã¯ãããªãã PHP/FI 2.0 ãã PHP 3.0 ãžç§»è¡ããéã«éé ããã§ãããéäºææ§ãšãããããžã®è§£æ±ºçã«ã€ããŠã®ã¬ã€ããæäŸ ããããšæããŸããå¿
èŠã§ãªãéããæ°ããæ©èœã«ã€ããŠã¯è¿°ã¹ãã㊠ããŸããã
|
This program only catches the syntax changes though, so you should read this chapter carefully anyway.
|
ããªãã®å€ã PHP/FI 2.0 ã¹ã¯ãªãããèªåçã«å€æã§ãã倿ããã°ã©ã ããããŸãããã㯠PHP 3.0 ãã£ã¹ããªãã¥ãŒã·ã§ã³ã® convertor ãµããã£ã¬ã¯ã㪠ã«ãããŸãããã®ããã°ã©ã ã¯ææ³çãªå€æŽãæãããã ãã§ãã®ã§ã ã©ã¡ãã«ããŠããã®ç« ãæ³šææ·±ãèªãå¿
èŠãããã§ãããã
|
Because of this, the syntax has been changed:
|
if(); elseif(); else; endif; ã䜿ã£ãŠ if/elseif/else ã¹ããŒãã¡ã³ãã èšè¿°ããããã® 'éžæè¢' ã«ã€ããŠã¯ã3.0 ããŒãµã«å¯ŸããŠããªãè€éãªåŠç ã远å ããŠãããªããšãå¹ççãªå®è£
ãè¡ãããšãã§ããŸããããã®ããã ææ³ã倿ŽãããŸããã
|
if ($foo); echo "yep\n"; elseif ($bar); echo "almost\n"; else; echo "nope\n"; endif;
|
äŸ C-5ç§»è¡ïŒå€ã if..endif ã®ææ³
|
if ($foo): echo "yep\n"; elseif ($bar): echo "almost\n"; else: echo "nope\n"; endif;
|
äŸ C-6ç§»è¡ïŒæ°ãã if..endif ã®ææ³
|
The old? form has been replaced by three new possible forms:
|
PHP ã®éå§ãšçµäºã®ã¿ã°ãå€ãã£ãŠããããšã«ãããããæåã«æ°ä»ããã ã§ããããå€ã? 圢åŒã¯ã3 ã€ã®æ°ãã 圢åŒã«çœ®ãæããããŸããã
|
? echo "This is PHP / FI 2.0 code.\n";?
|
äŸ C-1ç§»è¡ïŒå€ãéå§ïŒçµäºã¿ã°
|
? echo "This is PHP 3.0 code!\n";?
|
äŸ C-2ç§»è¡ïŒæåã®æ°ããéå§ïŒçµäºã¿ã°
|
?php echo "This is PHP 3.0 code!\n";?
|
äŸ C-3ç§»è¡ïŒ2 çªç®ã®æ°ããéå§ïŒçµäºã¿ã°
|
script language=" php "echo "This is PHP 3.0 code!\n"; / script
|
äŸ C-4ç§»è¡ïŒ3 çªç®ã®æ°ããéå§ïŒçµäºã¿ã°
|
$fp = fopen( $file, "r"); if ($fp == -1); echo("Could not open $file for reading br \n"); endif;
|
äŸ C-92.0 ããã®ç§»è¡ïŒè¿ãå€ãå€ãã³ãŒã
|
$fp = @fopen( $file, "r") or print("Could not open $file for reading br \n");
|
äŸ C-102.0 ããã®ç§»è¡ïŒè¿ãå€ãæ°ããã³ãŒã
|
The current possible PCRE modifiers are listed below.
|
çŸåšäœ¿çšå¯èœãªPCRE修食åã®äžèЧã以äžã«ç€ºããŸãã æ¬åŒ§ã®äžã®ååã¯ããããã®ä¿®é£Ÿåã«é¢ããPCREå
éšã®ååã§ãã
|
If this modifier is set, letters in the pattern match both upper and lower case letters.
|
ãã®ä¿®é£Ÿåãèšå®ãããŠããå Žåããã¿ãŒã³ã®äžã®æå㯠倧æåã«ãå°æåã«ããããããŸãã
|
The "start of line" metacharacter (^) matches only at the start of the string, while the "end of line "metacharacter ($) matches only at the end of the string, or before a terminating newline (unless D modifier is set).
|
ããã©ã«ãã§ãPCREã¯æ€çŽ¢å¯Ÿè±¡æååã(å®éã«ã¯è€æ°è¡ãããªã å Žåã§ã)åäžã®è¡ãããªããšããŠåŠçããŸãã "è¡é "ã¡ã¿æå (^) ã¯æååã®æåã«ãããããããŸããã äžæ¹ã"è¡ã®çµç«¯"ã¡ã¿æå ($) ã¯æååã®çµãããŸã㯠(D 修食åãèšå®ãããŠããªãå Žåã) çµç«¯ãè¡šãæ¹è¡èšå·ã®åã®ã¿ã«ãããããããŸããã ãã®åäœã¯ Perl ãšåãã§ãã
|
This is equivalent to Perl 's / m modifier.
|
ãã®ä¿®é£Ÿåãèšå®ãããå Žåã"è¡é "ããã³"è¡æ«"㯠subjectæååã«ãããŠãæååã®æåãšæåŸãšåãã«ã åæ¹è¡ã®çŽåãšçŽåŸã«ãããããããããŸãã ãã®åäœã¯ãPerl ã® /m 修食åãšåãã§ãã subject æååã®äžã« "\n" æåããªãå Žåã ãŸãã¯ãã¿ãŒã³ã« ^ ãŸã㯠$ããªãå Žåã ãã®ä¿®é£Ÿåãèšå®ããŠãæå³ã¯ãããŸããã
|
If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines.
|
ãã®ä¿®é£Ÿåãèšå®ãããå Žåããã¿ãŒã³äžã®ãããã¡ã¿æå㯠æ¹è¡ãå«ãå
šãŠã®æåã«ãããããŸãã ãããæå®ããªãå Žåãæ¹è¡ã¯é€ãããŸãã ãã®ä¿®é£Ÿåã¯ãPerl ã® /s 修食åãšç䟡ã§ãã [^a] ã®ãããªåŠå®ã¯ã©ã¹ã¯ã ãã®ä¿®é£Ÿåã®èšå®ã«ããããåžžã«æ¹è¡æåã«ãããããŸãã
|
A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.
|
ãã®ä¿®é£Ÿåãèšå®ãããå Žåããšã¹ã±ãŒãããã æåã¯ã©ã¹ã®å
éšã«ããå Žåãé€ãã ãã¿ãŒã³ã®ç©ºçœæåã¯å®å
šã«ç¡èŠãããŸãã ãšã¹ã±ãŒããããŠããªãæåã¯ã©ã¹ã®å€ã«ãã # ãšæ¬¡ã®æ¹è¡æåã®é ã®æåãç¡èŠãããŸãã ãã®åäœã¯ãPerl ã® /x 修食åãšåãã§ãããè€éãªãã¿ãŒã³ã®å
éšã« ã³ã¡ã³ããå«ãããšãå¯èœãšãªããŸãã ãããããã®ä¿®é£Ÿåã¯ãããŒã¿æåã«ã®ã¿é©çšãããããšã«æ³šæ ããŠäžãããç©ºçœæåããã¿ãŒã³ã®ç¹æ®æåã®äžŠã³ã®äžã äŸãã°æ¡ä»¶ä»ãµããã¿ãŒã³(?) ã®å
éšã«çœ®ãããšã¯ã§ããŸããã
|
This is equivalent to Perl 's / x modifier, and makes it possible to include comments inside complicated patterns.
|
ãã®ä¿®é£Ÿåãèšå®ãããŠããå Žåã preg_replace() ã¯ã眮ææååã«ãããŠåŸæ¹åç
§ã«é¢ããéåžžã®çœ®æãè¡ã£ãåŸã PHP ã³ãŒããšããŠè©äŸ¡ããæ€çŽ¢æååã眮æããããã«ãã®çµæã 䜿çšããŸãã
|
Whitespace characters may never appear within special character sequences in a pattern, for example within the sequence (? (which introduces a conditional subpattern.
|
ãã®ä¿®é£Ÿåã䜿çšããã®ã¯ã preg_replace() ã®ã¿ã§ãã ä»ã® PCRE 颿°ã§ã¯ç¡èŠãããŸãã
|
Only preg_replace() uses this modifier; it is ignored by other PCRE functions.
|
ãã®ä¿®é£Ÿåãèšå®ãããå Žåããã¿ãŒã³ã¯åŒ·å¶çã«"anchored"ãšãªããŸãã ãã®å Žåãæ€çŽ¢ãããæåå("æ€çŽ¢å¯Ÿè±¡æåå")ã®å
é ã« ã®ã¿ãããããããã«å¶éãããŸãã ãã¿ãŒã³èªäœã®äžã«é©åœãªæå®ãè¡ãããšã§ã åæ§ã®å¹æãåŸãããšãå¯èœã§ãPerlã§ã¯ãã®æ¹æ³ããäœ¿çš ã§ããŸããã
|
This effect can also be achieved by appropriate constructs in the pattern itself, which is the only way to do it in Perl.
|
ãã®ä¿®é£Ÿåãèšå®ãããŠããå Žåããã¿ãŒã³å
ã®ã¡ã¿èšå·ã®ãã« ã¯ãæ€çŽ¢å¯Ÿè±¡æååã®çµããã«ã®ã¿ãããããŸãã ãã®ä¿®é£Ÿåãæå®ããªãå Žåããã«èšå·ã¯æ¹è¡æåã®çŽåã® æå(ãã ããæ¹è¡æå以å€)ã«ããããããŸãã ãã®ä¿®é£Ÿåã¯ã m ãèšå®ãããŠããå Žåã« ç¡èŠãããŸãã Perlã«ã¯ããã®ä¿®é£Ÿåã«ç䟡ãªãã®ã¯ãããŸããã
|
Without this modifier, a dollar also matches immediately before the final character if it is a newline (but not before any other newlines).
|
ãããã¿ãŒã³ãè€æ°å䜿çšããå Žåããããã³ã°ã«ãããæéã é«éåããããšãç®çãšããŠããã¿ãŒã³è§£æã«ããæéãããã 䟡å€ããããŸãã ãã®ä¿®é£Ÿåãèšå®ããå Žåããã®ãããªããæéããããè§£æã è¡ãããŸããçŸåšããã¿ãŒã³è§£æã¯ã æåã®æåãåäžã®åºå®ãããŠããªãã¢ã³ã«ãŒä»ãã§ãªããã¿ãŒã³ã§ã®ã¿ æçšã§ãã
|
If this modifier is set, then this extra analysis is performed.
|
ãã®ä¿®é£Ÿåã¯ãããã©ã«ãã§è²ªæ¬²ã§ãªããã"?" ãåŸã«ä»ããšè²ªæ¬² ã«ãªãéåååšã®åäœãå転ããŸãããã®ä¿®é£Ÿåã¯Perläºæã§ã¯æ ããŸããããã®ä¿®é£Ÿåã®æå®ã¯ã(?U) 修食åã®ããã«ãã¿ãŒã³å
ã§ãè¡ãããšãã§ããŸãã
|
This modifier inverts the "greediness" of the quantifiers so that they are not greedy by default, but become greedy if followed by "?".
|
ãã®ä¿®é£Ÿåã¯ãPerl ãšäºææ§ããªã PCRE ã®ä»å çãªæ©èœããªã³ã«ããŸãã ãã¿ãŒã³å
ã§åŸãã«æåãç¶ãããã¯ã¹ã©ãã·ã¥ã§ç¹å¥ãªæå³ããªã ãã®ã¯ãå°æ¥çãªæ¡åŒµã®éã®äºææ§ã®ç¶æã®ããããšã©ãŒã«ãªããŸãã ããã©ã«ãã§ã¯ãPerl ã®ããã«æåãåŸãã«ç¶ãããã¯ã¹ã©ãã·ã¥ ã§ç¹ã«æå³ããªããã®ã¯ããªãã©ã«ãšããŠåŠçãããŸãã ãã®ä¿®é£Ÿåã«ããå¶åŸ¡ãããæ©èœã¯ãçŸåšä»ã«ãããŸããã
|
By default, as in Perl, a backslash followed by a letter with no special meaning is treated as a literal.
|
ãã®ä¿®æ£åã¯ãPerléäºæãªPCREã®æ©èœãæå¹ã«ããŸãããã¿ãŒã³ æååã¯ãUTF-8ãšã³ã³ãŒããããæååãšããŠåŠçãããŸããã ã®ä¿®æ£åã¯ãPHP-4.1.0以éã§äœ¿çšå¯èœã§ãã
|
Normally isspace() matches space, formfeed, newline, carriage return, horizontal tab, and vertical tab.
|
PCRE ã©ã€ãã©ãªã¯ã(以äžã«ç€ºã)å
ããªéããé€ã Perl 5 ãšåãæ§æãš æå³ã䜿çšããæ£èŠè¡šçŸãã¿ãŒã³ãããã³ã°ãå®è£
ãã颿°çŸ€ã§ãã çŸåšã®å®è£
ã¯ãPerl 5.005 ã«å¯Ÿå¿ããŠããŸãã
|
Capturing subpatterns that occur inside negative looka - head assertions are counted, but their entries in the offsets vector are never set.
|
ããã§èª¬æããã®ã¯ãPerl 5.005 ã«é¢é£ãããã®ã§ãã
|
For example, matching "aba" against the pattern / ^(a(b) ?)+$ / sets $2 to the value "b", but matching "aabbaa "against / ^(aa(bb)? )+$ / leaves $2 unset.
|
PCREã§ã¯ãå
èªã¿èšæ(assertion)æã«ç¹°ãè¿ãæ°ã®æå®ã䜿çšã§ã㟠ãããPerlã¯ãããèš±å¯ããŸãããæå³ããéãã«åäœããããšãæ å³ããããã§ã¯ãããŸãããäŸãã°ã(?!a){3} ã¯ã次ã®3æåã "a" ã§ãªãããšãèšæããããã§ã¯ãããŸããããã®æå®ã¯ãæ¬¡ã®æåã "a" ã§ã¯ãªãããšã3åèšæããã ãã§ãã
|
The syntax and semantics of the regular expressions sup - ported by PCRE are described below.
|
åŠå®ã®å
èªã¿èšæã®äžã§çãããµããã¿ãŒã³ãååŸããåæ°ã¯èšç®ã ããŸããããªãã»ãããã¯ãã«ã®äžã®å¯Ÿå¿ãããšã³ããªã¯èšå®ãã㟠ãããPerlã§ã¯ãèšæã®ãããã³ã°ã«å€±æããåã«ããããããã¿ãŒ ã³ãããã®å€æ°ãèšå®ããŸããããããè¡ãããã®ã¯ãåŠå®ã®å
èªã¿ èšæã®æã1ã€ã ãã®å Žåã®ã¿ã§ãã
|
Jeffrey Friedl' s "Mastering Regular Expressions", published by O'Reilly (ISBN 1-56592-257-3), covers them in great detail.
|
ãã«æåæåã¯ãæ€çŽ¢å¯Ÿè±¡æååã§ãµããŒããããŸããããã¿ãŒã³æ ååã§ã¯ãµããŒããããŸãããããã¯ããã¿ãŒã³æååã¯ã0ãçµç«¯ãš ããéåžžã®CæååãšããŠæž¡ãããããã§ãããšã¹ã±ãŒãã·ãŒã±ã³ã¹ "\0"ã¯ããã«æåã衚ããã¿ãŒã³ãšããŠäœ¿çšããããšãå¯èœã§ãã
|
There are two different sets of meta-characters: those that are recognized anywhere in the pattern except within square brackets, and those that are recognized in square brackets.
|
次ã®Perlãšã¹ã±ãŒãã·ãŒã±ã³ã¹ã¯ããµããŒããããŸããã: \l, \u, \L, \U, \E, \Q å®éãPerlã§ã¯ããããã¯ãã¿ãŒã³ãããã³ã°ãšã³ ãžã³ã®éšåã§ã¯ãªããéåžžã®æåååŠçã®éšåã«å®èšŒãããŠããŸãã
|
This use of backslash as an escape character applies both inside and outside character classes.
|
Perlã®\Gèšæã¯ãäžåã®ãã¿ãŒã³ãããã«é¢ãããã®ã§ã¯ãªãããã ãµããŒããããŸããã
|
This applies whether or not the follow - ing character would otherwise be interpreted as a meta - character, so it is always safe to precede a non-alphanumeric with "\" to specify that it stands for itself.
|
æç¢ºã«è¿°ã¹ããšãPCREã¯(?{code})æ§é ããµããŒãããŸããã
|
A description of how this works is given later, following the discussion of parenthesized subpatterns.
|
ä»ã®æªè§£æ±ºã®ççŸã¯ãPerl 5.005_02 ã§ã¯ããã¿ãŒã³ /^(a)?(?(1)a_BAR_b)+$/ ã¯æåå "a" ã«ãããããŸãããPCRE ã§ã¯ãã ãããªããšããããšã§ããããããPerl ãš PCRE ã¯å
±ã« /^(a)?a/ ã§ "a" ããããããå Žåã« $1 ãæªå®çŸ©ã®ãŸãŸãšãªããŸãã
|
All the sequences that define a single byte value can be used both inside and outside character classes.
|
PCREã¯ãPerlæ£èŠè¡šçŸã®æ©èœã«ããã€ãã®æ¡åŒµæ©èœãæäŸããŸãã
|
The definition of letters and digits is controlled by PCRE' s character tables, and may vary if locale-specific matching is taking place (see "Locale support "above).
|
å
èªã¿èšæã¯ãåºå®é·ã®æååã«ãããããå¿
èŠããããŸãããå
èªã¿èšæã®å¥ã®åæã¯ãç°ãªã£ãé·ãã®æååã«ãããããããšã ã§ããŸããPerl 5.005 ã§ã¯å
šãŠåãé·ãã§ããå¿
èŠããããŸãã
|
These character type sequences can appear both inside and outside character classes.
|
PCRE_DOLLAR_ENDONLY ã èšå®ãããŠããã PCRE_MULTILINE ãèšå® ãããŠããªãå Žåãã¡ã¿æå$ã¯ãæååã®çµç«¯ã«ã®ã¿ãããããŸãã
|
The use of subpatterns for more complicated assertions is described below.
|
PCRE_EXTRA ãèš å®ãããŠããå Žåãããã¯ã¹ã©ãã·ã¥ã®åŸã«æåããã£ãŠç¹ã«æå³ ããªããã®ã¯ããšã©ãŒãšãªããŸãã
|
They are not affected by the PCRE_NOTBOL or PCRE_NOTEOL options.
|
PCRE_UNGREEDY ã èšå®ãããŠããå Žåãããã©ã«ãã§ã¯è²ªæ¬²ã§ãªãç¹°ãè¿ãæå®å㮠貪欲ãã¯å転ããŸãããçå笊ãåŸãã«ã€ãå Žåã¯ã貪欲ã«ãªããŸãã
|
A closing squareA closing square bracket on its own is not special.
|
æ€çŽ¢å¯Ÿè±¡(è€æ°è¡ã¢ãŒãã§ã¯è¡)ã®å§ãŸããèšæ
|
Note that a circumflex is just a con - venient notation for specifying the characters which are inNote that a circumflex is just a con - venient notation for specifying the characters which are in the class by enumerating those that are not.
|
(ããã©ã«ãã§ã¯)æ¹è¡ãé€ãå
šãŠã®æåã«ããã
|
The newline character is never treated in any special way in character classes, whatever the setting of the PCRE_DOTALL or PCRE_MULTILINE options is.
|
æåã¯ã©ã¹éå§ãå®çŸ©
|
It is not possible to have the literal character "]" as theIt is not possible to have the literal character "] "as the end character of a range.
|
æåã¯ã©ã¹ã®çµäº
|
If a range that includes letters is used when caseless matching is set, it matches the letters in eitherIf a range that includes letters is used when caseless matching is set, it matches the letters in either case.
|
ãµããã¿ãŒã³ã®éå§
|
The character types \d, \D, \s, \S, \w, and \W may also appear in a character class, and add the characters thatThe character types \d, \D, \s, \S, \w, and \W may also appear in a character class, and add the characters that they match to the class.
|
ãµããã¿ãŒã³ã®çµäº
|
Vertical bar characters are used to separate alternativeVertical bar characters are used to separate alternative patterns.
|
(ã®æå³ãæ¡åŒµãããŸãã¯ã0 ãŸãã¯1 åã®ç¹°ãè¿ããŸãã¯ãç¹°ã è¿ããæå°åãã
|
The matching process tries each alternative in turn, from left to right, and the firstThe matching process tries each alternative in turn, from left to right, and the first one that succeeds is used.
|
0以äžã®ç¹°ãè¿ã
|
It is also possible to unset these options by preceding the letter with a hyphen, and a combined setting and unsetting such as (?im-sx), which sets PCRE_CASELESS and PCRE_MULTILINE while unsetting PCRE_DOTALL and PCRE_EXTENDED, is also permitted.
|
æå°/æå€§ç¹°ãè¿ãã®éå§
|
The following patterns all behave in exactly the same way: (?i)abc a(?i)bc ab(?i)c abc(?i) which in turn is the same as compiling the pattern abc with PCRE_CASELESS set.
|
æå°/æå€§ç¹°ãè¿ãã®çµäº
|
By this means, options can be made to have different settings in different parts of theBy this means, options can be made to have different settings in different parts of the pattern.
|
äžè¬çãªãšã¹ã±ãŒãæå
|
For example, (a(?i)b_BAR_c) matches "ab", "aB", "c", and "C", even though when matching "C "the first branch is abandoned before the option setting.
|
æåã®æåã«çšããå Žåã®ã¿ãã¯ã©ã¹ãåŠå®
|
Without the parentheses, it would match "cataract", "erpillar" or the empty string.
|
æåã¯ã©ã¹ãçµäºãã
|
When the whole pattern matches, that portion of the subject string that matched the subpattern is passed back to the caller via the ovector argument of pcre_exec().
|
ããã¯ã¹ã©ãã·ã¥ã«ã¯ãããã€ãã®äœ¿çšæ³ããããŸãããŸãã è±åã§ãªãæåãåŸã«ç¶ãå ŽåãããŠ?åãæãã ç¹å¥ãªæå³ã¯å€±ãããŸãããã®ããã¯ã¹ã©ãã·ã¥ã®äœ¿ãæ¹ã¯ã æåã¯ã©ã¹ã®å
åŽãšå€åŽã®äž¡æ¹ã§äœ¿çšå¯èœã§ãã
|
The fact that plain parentheses fulfil two functions is notThe fact that plain parentheses fulfil two functions is not always helpful.
|
äŸãã°ã"*" æåã«ãããããããå Žåããã¿ãŒã³ã« "\*" ãæžããŸãã ããã«ãããæ¬¡ã®æåãã¡ã¿æåãšããŠè§£éãããããšãããŸããšã "\" ã䌎ã£ãè±åã§ãªãæåãããã®æåèªäœã衚ãããšãä¿èšŒããŸãã ç¹ã«ãããã¯ã¹ã©ãã·ã¥ã«ãããããããå Žåã¯ã"\\" ãšæžããŸãã
|
The maximum number of captured substrings is 99, and the maximum number of all subpatterns, both capturing and non-capturing, is 200.
|
ããã¯ã¹ã©ãã·ã¥ã®2çªç®ã®äœ¿çšæ³ã¯ãåºåãããªãæåã ãã¿ãŒã³å
ã«ç®ã«èŠãã圢ã§ãšã³ã³ãŒãããææ³ãæäŸãããã®ã§ãã ãã¿ãŒã³ãçµäºããããã«æåãé€ããåºåãããªãæåã®èŠãæ¹ã« ã¯äœã®å¶çŽããããŸãããããã¿ãŒã³ãããã¹ãç·šéããéã«ã¯ãéåžž 次ã®ãšã¹ã±ãŒãã·ãŒã±ã³ã¹ãçšããæ¹ããå
ã®ãã€ããªæåããã ããç°¡åã§ãããã
|
Thus the two patterns (?i:saturday_BAR_sunday) (? :(?i)saturday_BAR_sunday)Thus the two patterns (?i:saturday_BAR_sunday) (? :(?i)saturday_BAR_sunday) match exactly the same set of strings.
|
ã¢ã©ãŒã ããã«æå (16é² 07)
|
The numbers must be less than 65536, and the first must beThe numbers must be less than 65536, and the first must be less than or equal to the second.
|
"control-x", ãã ã x ã¯ããããæå
|
Thus [aeiou]{3,} matches at least 3 successive vowels, but may match many more, while \d{8}Thus [aeiou]{3,} matches at least 3 successive vowels, but may match many more, while \d{8} matches exactly 8 digits.
|
ãšã¹ã±ãŒã (16é² 1B)
|
However, because there are cases where this can be useful, such patterns are now accepted, but if any repetition of the subpattern does in fact match no characters, the loop is forcibly broken.
|
æ¹ããŒãž (16é² 0C)
|
The classic example of where this gives problems is inThe classic example of where this gives problems is in trying to match comments in C programs.
|
æ¹è¡ (16é² 0A)
|
An attempt to match C comments by applying the pattern / \*.*\* / to the string / * first command * / not comment / * second comment * / fails, because it matches the entire string due to the greediness of the .* item.
|
埩垰 (16é² 0D)
|
The meaning of the various quantifiers is not otherwise changed, just the preferredThe meaning of the various quantifiers is not otherwise changed, just the preferred number of matches.
|
ã¿ã (16é² 09)
|
When a capturing subpattern is repeated, the value capturedWhen a capturing subpattern is repeated, the value captured is the substring that matched the final iteration.
|
8鲿°ã§ ddd ã®æåãŸãã¯åŸæ¹åç
§
|
However, if there are nested capturing subpatterns, the corresponding capturedHowever, if there are nested capturing subpatterns, the corresponding captured values may have been set in previous iterations.
|
"\cx" ã®æ£ç¢ºãªå¹æã¯ã次ã®ããã«ãªããŸãã"x" ãå°æåã®å Žåã 倧æåã«å€æãããŸããç¶ããŠãæåã®6ãããç®(16鲿° 40)ã å転ãããŸããã€ãŸãã"\cz" ã¯16鲿°ã® 1A ã«ãªããŸããã"\c{" ã¯16鲿°ã® 3B ã«ãªãã"\c;" 㯠16鲿°ã® 7B ã«ãªããŸãã
|
In other words, the parentheses that are referenced need not be to the left ofIn other words, the parentheses that are referenced need not be to the left of the reference for numbers less than 10.
|
"\x" ã®åŸã§ã¯ã2æ¡ã®16鲿°ãèªãŸããŸãã(衚ãæåã¯ã倧æåã§ã å°æåã§ãå¯ã§ã)"\0"ã§ã¯2æ¡ãŸã§ã®8鲿°ãèªã¿ããŸããŸãã äž¡æ¹ã®ã±ãŒã¹ãšãã2æ¡ããå°ãªãå Žåã衚ããŠããæåèªäœã 䜿çšãããŸããã€ãŸãã"\0\x\07" ã¯2ã€ã®ãã«æåã®åŸã«ãã«æå ãç¶ãããã®ã衚ããŸãã8鲿°ã衚ãæåã«ã€ããŠã¯ãæåã®ãŒã ã®åŸã«2æ¡ã®æ°åãæå®ããããã«æ³šæããŠäžããã
|
If caseful matching is in force at the time of the back reference, thenIf caseful matching is in force at the time of the back reference, then the case of letters is relevant.
|
ããã¯ã¹ã©ãã·ã¥ã®åŸã«0以å€ã®æ°åãç¶ãå Žåã®åŠçã¯ãè€éã§ãã æåã¯ã©ã¹ã®å€ã§ã¯ãPCRE ã¯ç¶ãæ¡ã10鲿°ãšããŠèªã¿ãã¿ãŸãã æ°åã10ãããå°ããå ŽåããŸãã¯ãåŒã®äžã«å€ãååŸããå·Šæ¬åŒ§ã ãã®æ°ä»¥äžãã£ãå Žåãå
šäœã®ã·ãŒã±ã³ã¹ã¯ã åŸæ¹ åç
§ ãšããŠè§£éãããŸãããã®åäœã«é¢ãã説æ ã¯ãæ¬åŒ§ä»ãã®ãµããã¿ãŒã³ã®èª¬æã®åŸã«è¡ããŸãã
|
For example, the pattern (a_BAR_(bc))\2 always fails if it starts to match "a "rather than "bc".
|
æåã¯ã©ã¹ã®äžãŸãã¯10鲿°ã9ãã倧ãããååŸãè¡ã£ããµããã¿ãŒã³ ããã®æ°ã«æºããªãå ŽåãPCRE ã¯ããã¯ã¹ã©ãã·ã¥ã®åŸããæå€§3æåã®8鲿° ãå床èªã¿ãã¿ããã®å€ã®æäžäœ 8ããããã1ãã€ããçæããŸãã ç¶ãæ¡ã¯ããèªäœã衚ããŸããäŸãã°ã
|
If the pattern continues with a digit character, then some delimiter must be used to terminate theIf the pattern continues with a digit character, then some delimiter must be used to terminate the back reference.
|
ã¯ç©ºçœã®å¥ã®è¡šèšæ³ã§ãã
|
At each iteration of the subpattern, the back reference matches the character string corresponding to the previous iteration.
|
ã¯ãåãæå³ã§ãããã ããå€ãååŸæžã¿ã®ãµããã¿ãŒã³ã40åæª æºã®å Žåã
|
The simple assertions coded as \b,The simple assertions coded as \b, \B, \A, \Z, \z, ^ and $are described above.
|
ã¯åžžã«åŸæ¹åç
§ã§ãã
|
There are two kinds: those that look ahead of the current position in the subject string, and those that look behind it.
|
ã¯åŸæ¹åç
§ãŸãã¯ã¿ãã®å¥ã®è¡šèšæ³ã§ãã
|
Lookahead assertions start with (?= for positiveLookahead assertions start with (?= for positive assertions and (?! for negative assertions.
|
ã¯åžžã«ã¿ãã§ãã
|
Lookbehind assertions start with (? = for positive assertionsLookbehind assertions start with (? = for positive assertions and (?! for negative assertions.
|
(99 ãè¶
ããåŸæ¹åç
§ã¯ãªãã®ã§) 8鲿° 113 ã衚ãæåã
|
The contents of a lookbehind assertion are restricted such that all the strings it matches must have a fixedThe contents of a lookbehind assertion are restricted such that all the strings it matches must have a fixed length.
|
ã¯1ãããã®äžŠã³ã§æ§æããã1ãã€ãã§ãã
|
Thus (? =bullock_BAR_donkey) is permitted, but (? !dogs ?_BAR_cats ?)Thus (? =bullock_BAR_donkey) is permitted, but (? !dogs ?_BAR_cats?) causes an error at compile time.
|
ã¯åŸæ¹åç
§ãŸãã¯ããã«æåã®åŸã«2ã€ã®æå "8" ããã³ "1" ã ç¶ãããã®ã§ãã
|
This is an extension compared with Perl 5.005, which requires all branches to match the sameThis is an extension compared with Perl 5.005, which requires all branches to match the same length of string.
|
3æ¡ãè¶
ããŠ8鲿°ã¯èªã¿ããŸããªããããå€ã100以äžã®8鲿°ã«ã¯ ãŒããåã«ã€ããã¹ãã§ã¯ãªãããšã«æ³šæããŠãã ããã
|
Lookbehinds in conjunction with once-only subpatterns can be particularly useful for matching at the ends of strings; an example is given at the end of the section on once-only subpatterns.
|
1ãã€ãã®å€ãå®çŸ©ããããããã·ãŒã±ã³ã¹ã¯ãæåã¯ã©ã¹ã®å
éš ããã³å€éšã§äœ¿çšå¯èœã§ããå ããŠãæåã¯ã©ã¹ã®å
éšã§ã¯ã·ãŒã±ã³ã¹ "\b" ã¯ããã¯ã¹ããŒã¹(16é² 0x)ãšããŠè§£éãããŸãã æåã¯ã©ã¹ã®å€ã§ã¯ãå¥ã®æå³ãæããŸãã(以äžãåç
§äžãã)
|
Notice that each of the assertions is applied independentlyNotice that each of the assertions is applied independently at the same point in the subject string.
|
ããã¯ã¹ã©ãã·ã¥ã®ç¬¬3ã®äœ¿çšæ³ã¯ãå
æ¬çãªæååãæå®ããçšé ã§ãã
|
This pattern does not match "foo" preceded by six characters, the first of which are digits and the last threeThis pattern does not match "foo "preceded by six characters, the first of which are digits and the last three of which are not "999".
|
10鲿°å
|
However, substring capturing is carried out only for positive assertions, because it does not make sense for negative assertions.
|
ç©ºçœæå
|
An alternative description is that a subpattern of this type matches the string of characters that an identical standalone pattern would match, if anchored at the current point in the subject string.
|
ãšã¹ã±ãŒãã·ãŒã±ã³ã¹ã®åçµã¯ãå
šæåã®éåã2ã€ã®éåã« åå²ããŸããå
šãŠã®æåã¯ãåçµã®ãã¡ãçæ¹ã ?kãããããŸãã
|
So, while both \d + and \d+? are prepared to adjust the number of digits they match in order to make the rest of the pattern match, (? \d+) can only match an entire sequence of digits.
|
åèªæ§ææåãšã¯è±åãŸãã¯æ°åãŸãã¯ã¢ã³ããŒã¹ã³ã¢æåã§ããã Perl ã® "åèª" ãšæãåŸãæåã®ããšã§ãã æåããã³æ°åã®å®çŸ©ã¯ãPCRE ã®æåããŒãã«ã«ããå¶åŸ¡ããã ãã±ãŒã«ãæå®ããããããè¡ã£ãå Žåã«ã¯å€ããå¯èœæ§ããããŸãã ("ãã±ãŒã«ã®ãµããŒã"ãåç
§äžãã) äŸãã°ã"fr" (ãã©ã³ã¹èª)ãã±ãŒã«ã®å Žåãããã€ãã®128ãè¶
ãã æåã³ãŒãã®æåã¯ãã¢ã¯ã»ã³ãä»ãã®æåã«äœ¿çšãããŠããã ããã㯠\w ã«ãããããŸãã
|
Consider a simple pattern such as abcd$Consider a simple pattern such as abcd$ when applied to a long string which does not match.
|
ãããã®æååã·ãŒã±ã³ã¹ã¯ãæåã¯ã©ã¹ã®å
å€ã«ããã䜿çšå¯èœ ã§ãããããã¯ãé©åœãªåã®1æåã«ãããããŸããçŸåšãããã³ã° ãè¡ã£ãŠããäœçœ®ãæ€çŽ¢å¯Ÿè±¡æååã®çµç«¯ã§ããå Žåããããã§ãã æåã¯ãªãã®ã§å
šãŠã®ãããã³ã°ã¯å€±æããŸãã
|
However, if the pattern is written as ^(? .*)(? =abcd) then there can be no backtracking for the .* item; it canHowever, if the pattern is written as ^(? .*)(? =abcd) then there can be no backtracking for the .* item; it can match only the entire string.
|
ããã¯ã¹ã©ãã·ã¥ã®ç¬¬4ã®äœ¿çšæ³ã¯ãåçŽãªèšæã§ãã èšæã¯ãæ€çŽ¢å¯Ÿè±¡æååããæåãå
šãæãåºããã« ããããç¹å®ã®äœçœ®ã§çãããšããæææ¡ä»¶ãæå®ããŸãã ããè€éãªèšæã«é¢ãããµããã¿ãŒã³ã®äœ¿çšæ³ã以äžã«èª¬æããŸãã ããã¯ã¹ã©ãã·ã¥ä»ãã®èšæã¯æ¬¡ã®ãã®ããããŸãã
|
There are two kinds of condition.
|
æ€çŽ¢å¯Ÿè±¡ã®çµãããŸãã¯çµç«¯ã®æ¹è¡ (è€æ°è¡ã¢ãŒããšã¯ç¬ç«)
|
The third part is a conditional subpattern that tests whether the first set of parenthesesThe third part is a conditional subpattern that tests whether the first set of parentheses matched or not.
|
ãããã®èšæã¯ãæåã¯ã©ã¹ã«ã¯äœ¿çšã§ããŸããã(ããããæåã¯ã©ã¹ã® äžã§ã¯ã" \b "ã«ã¯å¥ã®æå³ãã€ãŸããããã¯ã¹ããŒ ã¹æåãšããæå³ãããããšã«æ³šæããŠãã ãã)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.