Using regular expressions when reading a file

H. S. Teoh hsteoh at quickfur.ath.cx
Thu May 5 18:58:41 UTC 2022


On Thu, May 05, 2022 at 06:50:17PM +0000, Alexander Zhirov via Digitalmars-d-learn wrote:
> On Thursday, 5 May 2022 at 18:15:28 UTC, H. S. Teoh wrote:
> > 	auto m = matchFirst(line, p_property);
> 
> Yes, it looks more attractive. Thanks! I just don't quite understand how
> `matchFirst` works. I seem to have read the
> [description](https://dlang.org/phobos/std_regex.html#Captures), but I can't
> understand something.
> 
> And yet I have to manually remove the line break:
> ```sh
> ["host":"192.168.100.236\n", "dbname":"belpig\n", "user":"postgres",
> "port":"5432\n"]
> ```

You don't have to. Just add a `$` to the end of your regex, and it
should match the newline. If you put it outside the capture parentheses,
it will not be included in the value.


T

-- 
In a world without fences, who needs Windows and Gates? -- Christian Surchi


More information about the Digitalmars-d-learn mailing list