Re: Using regular expressions when reading a file

2022-05-06 Thread novice2 via Digitalmars-d-learn
imho, regexp is overkill here. as for me, i usually just split line for first '=', then trim spaces left and right parts.

Re: Using regular expressions when reading a file

2022-05-06 Thread forkit via Digitalmars-d-learn
On Friday, 6 May 2022 at 07:51:01 UTC, Alexander Zhirov wrote: On Friday, 6 May 2022 at 05:40:52 UTC, forkit wrote: auto myTuple = line.split(" = "); Well, only if as a strict form :) well.. a settings file should be following a strict format. ..otherwise...anything goes... and good luck wi

Re: Using regular expressions when reading a file

2022-05-06 Thread Alexander Zhirov via Digitalmars-d-learn
On Friday, 6 May 2022 at 05:40:52 UTC, forkit wrote: auto myTuple = line.split(" = "); Well, only if as a strict form :)

Re: Using regular expressions when reading a file

2022-05-05 Thread forkit via Digitalmars-d-learn
On Thursday, 5 May 2022 at 17:53:57 UTC, Alexander Zhirov wrote: I want to use a configuration file with external settings. I'm trying to use regular expressions to read the `Property = Value` settings. I would like to do it all more beautifully. Is there any way to get rid of the line break ch

Re: Using regular expressions when reading a file

2022-05-05 Thread Alexander Zhirov via Digitalmars-d-learn
On Thursday, 5 May 2022 at 19:19:26 UTC, Ali Çehreli wrote: Couldn't help myself from improving. :) The following regex works in my Linux console. No issues with '\n'. (?) It also allows for leading and trailing spaces: import std.regex; import std.stdio; import std.algorithm; import std.array

Re: Using regular expressions when reading a file

2022-05-05 Thread Ali Çehreli via Digitalmars-d-learn
On 5/5/22 12:05, Alexander Zhirov wrote: On Thursday, 5 May 2022 at 18:58:41 UTC, H. S. Teoh wrote: 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. In fact, it tur

Re: Using regular expressions when reading a file

2022-05-05 Thread Alexander Zhirov via Digitalmars-d-learn
On Thursday, 5 May 2022 at 18:58:41 UTC, H. S. Teoh wrote: 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. In fact, it turned out to be much easier. It was just nec

Re: Using regular expressions when reading a file

2022-05-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 05, 2022 at 06:50:17PM +, 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.

Re: Using regular expressions when reading a file

2022-05-05 Thread Alexander Zhirov via Digitalmars-d-learn
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

Re: Using regular expressions when reading a file

2022-05-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 05, 2022 at 05:53:57PM +, Alexander Zhirov via Digitalmars-d-learn wrote: > I want to use a configuration file with external settings. I'm trying > to use regular expressions to read the `Property = Value` settings. I > would like to do it all more beautifully. Is there any way to

Using regular expressions when reading a file

2022-05-05 Thread Alexander Zhirov via Digitalmars-d-learn
I want to use a configuration file with external settings. I'm trying to use regular expressions to read the `Property = Value` settings. I would like to do it all more beautifully. Is there any way to get rid of the line break character? How much does everything look "right"? **settings.conf