| View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] |
| ID | Project | Category | View Status | Date Submitted | Last Update |
| 0003969 | OCaml | OCaml general | public | 2006-02-02 22:56 | 2006-03-29 16:27 |
|
| Reporter | rillig | |
| Assigned To | | |
| Priority | normal | Severity | feature | Reproducibility | always |
| Status | acknowledged | Resolution | open | |
| Platform | | OS | | OS Version | |
| Product Version | 3.09.0 | |
| Target Version | | Fixed in Version | | |
|
| Summary | 0003969: Regular expressions should support non-capturing groups |
| Description | In Perl, one can write qr"start(?:alt1|alt2|alt3)(.*)end" to compile a regular expression that has only one capturing group, namely the second one. The first "group" is just an alternative. I have written a patch to support this feature in O'Caml too, since I don't know of another way to write the regexp above that is similarly short and readable.
|
| Additional Information | Unfortunately, this patch might change the behavior of some regular expressions that look like foo\(?, because a question mark that appears at the start of a regular expression is taken literally.
|
| Tags | No tags attached. |
|
| Attached Files | patch-ca [^] (660 bytes) 2006-02-02 22:56 [Show Content] [Hide Content]$NetBSD$
--- otherlibs/str/str.ml.orig 2005-11-07 16:59:04.000000000 +0100
+++ otherlibs/str/str.ml 2006-01-26 13:01:59.000000000 +0100
@@ -503,6 +503,13 @@ let parse s =
'|' | ')' ->
assert false
| '(' ->
+ if i + 2 < len && s.[i+1] = '?' && s.[i+2] = ':' then
+ let (r, j) = regexp0 (i+3) in
+ if j + 1 < len && s.[j] = '\\' && s.[j+1] = ')' then
+ (r, j + 2)
+ else
+ failwith "\\( group not closed by \\)"
+ else
let group_no = !group_counter in
if group_no < 32 then incr group_counter;
let (r, j) = regexp0 (i+1) in
|
|