regex issue
Jay Norwood
jayn at prismnet.com
Mon Mar 19 12:24:29 PDT 2012
On Monday, 19 March 2012 at 13:55:39 UTC, Dmitry Olshansky wrote:
> That's right, however counting is completely separate from
> regex, you'd want to use std.algorithm count:
> count(match(....,"\n"));
>
> or more unicode-friendly:
> count(match(...., regex("$","m")); //note the multi-line flag
This only sets l_cnt to 1
void wcp_cnt_match1 (string fn)
{
string input = cast(string)std.file.read(fn);
enum ctr = ctRegex!("$","m");
ulong l_cnt = std.algorithm.count(match(input,ctr));
}
This works ok, but though concise it is not very fast
void wcp (string fn)
{
string input = cast(string)std.file.read(fn);
ulong l_cnt = std.algorithm.count(input,"\n");
}
>
> Also observe that there is simply no way to get more then
> constant number of submatches.
>
>>
>> (regex) Matches subexpression regex, saving matched portion of
>> text for
>> later retrival.
>>
>
> An example of unicode properties:
> \p{WhiteSpace} matches any unicode whitespace char
This fails to build, so I'd guess is missing \p
void wcp (string fn)
{
enum ctr = ctRegex!("\p{WhiteSpace}","m");
}
------ Build started: Project: a7, Configuration: Release Win32
------
Building Release\a7.exe...
a7.d(210): undefined escape sequence \p
Building Release\a7.exe failed!
Details saved as "file://G:\d\a7\a7\Release\a7.buildlog.html"
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========
More information about the Digitalmars-d-learn
mailing list