Reading .txt File into String and Matching with RegEx

BoQsc vaidas.boqsc at gmail.com
Sun Dec 10 19:11:03 UTC 2023


This is something I've searched on the forum and couldn't find 
exact answer.

TLDR: `r"^."` is matching the very first two character in the 
`input` string.

**matchtest.d**
```
import std.stdio : writeln;
import std.regex : matchAll;
import std.file  : read;

void main(){

	string input = cast(string)read("example.txt");
	writeln(matchAll(input, r"^."));

}
```

**Input(example.txt)**
```
HelloWorld
```

**Output**
```
rdmd matchtest.d
[["He"]]
```

https://dlang.org/phobos/std_regex.html#matchAll
https://dlang.org/library/std/file/read.html


More information about the Digitalmars-d-learn mailing list