Re: Reading .txt File into String and Matching with RegEx

2023-12-11 Thread BoQsc via Digitalmars-d-learn
Matches function declarations and captures function names from `.d` Source Code file **regexcapture.d** ``` import std.stdio : writeln; import std.regex : matchAll, regex; import std.file : read; void main(){ string input = cast(string)read("sourcecode.d"); foreach(match

Re: Reading .txt File into String and Matching with RegEx

2023-12-11 Thread BoQsc via Digitalmars-d-learn
eed two dots to match two characters? Each dot being the regex to match a single character, so `r"^.."` instead of `r"^."` to get the first two characters. When I run your program (on linux with rdmd from DMD 2.106.0), I get: [["H"]] Yeah, that's true,

Re: Reading .txt File into String and Matching with RegEx

2023-12-10 Thread thinkunix via Digitalmars-d-learn
BoQsc via Digitalmars-d-learn wrote: 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. Don't you need two dots to match two characters? Each dot being th

Reading .txt File into String and Matching with RegEx

2023-12-10 Thread BoQsc via Digitalmars-d-learn
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

Re: regex matching but not capturing

2023-04-06 Thread Ali Çehreli via Digitalmars-d-learn
On 4/6/23 11:08, Paul wrote: ways to access those repetitive ", cc" s on the end.  I don't think my regex is capturing them. Some internets think you are in parser territory: https://stackoverflow.com/questions/1407435/how-do-i-regex-match-with-grouping-with-unknown-number-of-groups Ali

Re: regex matching but not capturing

2023-04-06 Thread Paul via Digitalmars-d-learn
(current line that matches), c[1] will contain the first captured match ("AA" for first line), c.front[2] will contain "0" for first line, etc. Thanks Alex. Read some more and tried some different ways to access those repetitive ", cc" s on the end. I don't think my regex is capturing them.

Re: regex matching but not capturing

2023-04-06 Thread Alex Bryan via Digitalmars-d-learn
On Thursday, 6 April 2023 at 15:52:16 UTC, Paul wrote: My regex is matching but doesnt seem to be capturing. You may recognize this from the AOC challenges. file contains... **Valve AA has flow rate=0; tunnels lead to valves DD, II, BB** **Valve BB has flow rate=13; tunnels lead to valves CC

regex matching but not capturing

2023-04-06 Thread Paul via Digitalmars-d-learn
My regex is matching but doesnt seem to be capturing. You may recognize this from the AOC challenges. file contains... **Valve AA has flow rate=0; tunnels lead to valves DD, II, BB** **Valve BB has flow rate=13; tunnels lead to valves CC, AA** **Valve CC has flow rate=2; tunnels lead to valves

Re: Read a text file at once for regex searching

2023-03-20 Thread Paul via Digitalmars-d-learn
On Monday, 20 March 2023 at 17:47:19 UTC, Adam D Ruppe wrote: On Monday, 20 March 2023 at 17:42:17 UTC, Paul wrote: Do we have some such function in our std library? Try static import std.file; string s = std.file.readText("filename.txt"); http://phobos.dpldocs.info/std.file.readText.html

Re: Read a text file at once for regex searching

2023-03-20 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 20 March 2023 at 17:42:17 UTC, Paul wrote: Do we have some such function in our std library? Try static import std.file; string s = std.file.readText("filename.txt"); http://phobos.dpldocs.info/std.file.readText.html

Read a text file at once for regex searching

2023-03-20 Thread Paul via Digitalmars-d-learn
I've been looking through our Library documentation and having trouble finding what I want. **I'd like to read a text file in all at once** and do some searching and analytics on it instead of reading it bit by bit or line by line. Do we have some such function in our std library? Thanks in

Re: How to select the regex that matches the first token of a string?

2021-07-03 Thread vnr via Digitalmars-d-learn
corresponding regular expression, here is the code I currently have: [...] storing the regex in a token is an antipattern. Thank you for the answer, I know it's not clean, I'll modify my code to define a token type table with their regular expression and define a token type table wit

Re: How to select the regex that matches the first token of a string?

2021-07-03 Thread user1234 via Digitalmars-d-learn
have: [...] storing the regex in a token is an antipattern.

How to select the regex that matches the first token of a string?

2021-07-03 Thread vnr via Digitalmars-d-learn
{ /// The token type string type; /// The regex to match the token Regex!char re; /// The matched string string matched = null; } /// Function to find the right token in the given table Token find(Token[] table, const(Captures!string delegate(Token) pure @safe) fn

Re: find regex in backward direction ?

2020-12-19 Thread Виталий Фадеев via Digitalmars-d-learn
"ab\w" or "(?Pregex)" should be parsing: [ "a", "b", "\w" ], [ "(", "?", "P", "", "regex", ")"]..., i think. up.

Re: find regex in backward direction ?

2020-12-19 Thread Виталий Фадеев via Digitalmars-d-learn
{ last = m; } matchedLength = last.hit.length; return last.pre.length; } } Thank! Fastest solution wanted! May be... some like a "RightToLeft" in Win32 API... https://docs.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regexoptions?view=net-5.0#System_Text_RegularExpressions_RegexOptions_RightToLeft but how on Linux? MS-regex and Linux-regex is identical ?

Re: find regex in backward direction ?

2020-12-19 Thread kdevel via Digitalmars-d-learn
On Saturday, 19 December 2020 at 12:52:54 UTC, Виталий Фадеев wrote: Goal: size_t pos = findRegexBackward( r"abc"d ); assert( pos == 4 ); module LastOccurrence; size_t findRegexBackward_1 (dstring s, dstring pattern) { import std.regex : matchAll; auto results = matchAll (s, pat

find regex in backward direction ?

2020-12-19 Thread Виталий Фадеев via Digitalmars-d-learn
We have: dstring s = "abc3abc7"; Source: https://run.dlang.io/is/PtjN4T Goal: size_t pos = findRegexBackward( r"abc"d ); assert( pos == 4 ); How to find regex in backward direction ?

Re: regex: ] in a character class

2020-12-12 Thread Tobias Pankrath via Digitalmars-d-learn
On Saturday, 12 December 2020 at 12:03:49 UTC, kdevel wrote: I don't have a suggestion for better wording yet. [1] https://dlang.org/phobos/std_regex.html This [1] is how I would word it. [1] https://github.com/dlang/phobos/pull/7724

Re: regex: ] in a character class

2020-12-12 Thread Tobias Pankrath via Digitalmars-d-learn
On Saturday, 12 December 2020 at 12:03:49 UTC, kdevel wrote: In some situations a ] must be escaped as in auto re = regex(`^[a\]]$`); // match a and ] only Unfortunately dmd/phobos does not warn if you forget the backslash: auto re = regex(`^[a]]$`); // match a] This leads me to the

regex: ] in a character class

2020-12-12 Thread kdevel via Digitalmars-d-learn
In some situations a ] must be escaped as in auto re = regex(`^[a\]]$`); // match a and ] only Unfortunately dmd/phobos does not warn if you forget the backslash: auto re = regex(`^[a]]$`); // match a] This leads me to the documentation [1] which says \c where c is one of

Re: Regex and manipulating files

2020-11-16 Thread Jack via Digitalmars-d-learn
0) Run the script with some options 1) sed/grep regex to catch a portion of a file. For example: it finds the line that match "1234" and take all the lines until the line that match "abcd". 2) sed regex to catch some strings For example: "abc sdfs#=8 // some text&qu

Regex and manipulating files

2020-11-16 Thread Bloris via Digitalmars-d-learn
I've to convert a linux dash script because it is too slow and i decded to do it in D. I'm totally new to this and i think it could be a good exercise to learn this language. The shell script does some simple jobs like: 0) Run the script with some options 1) sed/grep regex to catch

Re: Regex split ignoore empty and whitespace

2020-02-20 Thread Ali Çehreli via Digitalmars-d-learn
hat extra '+' in the regex pattern: std.regex.split(l, ctRegex!`[\s-\)\(\.]+`) Ali

Re: Regex split ignoore empty and whitespace

2020-02-20 Thread Ali Çehreli via Digitalmars-d-learn
On 2/20/20 2:02 PM, AlphaPurned wrote:> std.regex.split(l, ctRegex!`[\s-\)\(\.]`); > > I'm trying too split a string on spaces and stuff... but it is returning > empty strings and other matches(e.g., ()). > > I realize I can delete afterwards but is there a direct way from split > or ctRegex? It

Regex split ignoore empty and whitespace

2020-02-20 Thread AlphaPurned via Digitalmars-d-learn
std.regex.split(l, ctRegex!`[\s-\)\(\.]`); I'm trying too split a string on spaces and stuff... but it is returning empty strings and other matches(e.g., ()). I realize I can delete afterwards but is there a direct way from split or ctRegex?

Re: Error on using regex in dmd v2.088.1

2020-02-03 Thread Andrea Fontana via Digitalmars-d-learn
On Monday, 3 February 2020 at 07:11:34 UTC, Dharmil Patel wrote: On Monday, 3 February 2020 at 07:03:03 UTC, Dharmil Patel wrote: In my code I am using regex like this: auto rgxComma = regex(r","); On compiling with dmd v2.076.1, it compiles successfully, but on compilin

Re: Error on using regex in dmd v2.088.1

2020-02-02 Thread Dharmil Patel via Digitalmars-d-learn
On Monday, 3 February 2020 at 07:03:03 UTC, Dharmil Patel wrote: In my code I am using regex like this: auto rgxComma = regex(r","); On compiling with dmd v2.076.1, it compiles successfully, but on compiling with dmd v2.088.1, I am getting lots of errors like: /src/phobos

Error on using regex in dmd v2.088.1

2020-02-02 Thread Dharmil Patel via Digitalmars-d-learn
In my code I am using regex like this: auto rgxComma = regex(r","); On compiling with dmd v2.076.1, it compiles successfully, but on compiling with dmd v2.088.1, I am getting lots of errors like: /src/phobos/std/regex/internal/thompson.d-mixin-836(837): Error: templat

Re: CT regex in AA at compile time

2020-01-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/7/20 11:00 AM, Taylor Hillegeist wrote: On Tuesday, 7 January 2020 at 15:51:21 UTC, MoonlightSentinel wrote: On Tuesday, 7 January 2020 at 15:40:58 UTC, Taylor Hillegeist wrote: but I can't get it to work. it says its an Error: non-constant expression. I imagine this has to do with the c

Re: CT regex in AA at compile time

2020-01-07 Thread Patrick Schluter via Digitalmars-d-learn
On Tuesday, 7 January 2020 at 15:40:58 UTC, Taylor Hillegeist wrote: I'm trying to trick the following code snippet into compilation. enum TokenType{ //Terminal Plus, Minus, LPer, RPer, Number, } static auto Regexes =[ TokenType.Plus: ctRegex!

Re: CT regex in AA at compile time

2020-01-07 Thread Taylor Hillegeist via Digitalmars-d-learn
re is a better way? Does anyone know? This issue is unrelated to ctRegex, AA literals are non-constant expressions (probably due to their implementation). You can work around this by using module constructors or lazy initialisation inside of a function: static Regex!char[TokenType] Re

Re: CT regex in AA at compile time

2020-01-07 Thread MoonlightSentinel via Digitalmars-d-learn
Regex, AA literals are non-constant expressions (probably due to their implementation). You can work around this by using module constructors or lazy initialisation inside of a function: static Regex!char[TokenType] Regexes; shared static this() { Regexes = [ TokenType.Plus: ct

CT regex in AA at compile time

2020-01-07 Thread Taylor Hillegeist via Digitalmars-d-learn
I'm trying to trick the following code snippet into compilation. enum TokenType{ //Terminal Plus, Minus, LPer, RPer, Number, } static auto Regexes =[ TokenType.Plus: ctRegex!(`^ *\+`), TokenType.Minus: ctRegex!(`^ *\-`), TokenType.LPer:

Re: using regex at compile time errors out! Error: static variable `thompsonFactory` cannot be read at compile time

2019-10-04 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 3 October 2019 at 23:47:17 UTC, Brett wrote: Error: static variable `thompsonFactory` cannot be read at compile time std.regex isn't ctfe compatible, alas. even the ctRegex doesn't work at ctfe; it *compiles* the regex at compile time, but it is not capable of actuall

Re: using regex at compile time errors out! Error: static variable `thompsonFactory` cannot be read at compile time

2019-10-04 Thread Brett via Digitalmars-d-learn
On Friday, 4 October 2019 at 10:07:40 UTC, kinke wrote: Have you tried ctRegex? Yes, just another error about something else that I don't remember.

Re: using regex at compile time errors out! Error: static variable `thompsonFactory` cannot be read at compile time

2019-10-04 Thread kinke via Digitalmars-d-learn
Have you tried ctRegex?

using regex at compile time errors out! Error: static variable `thompsonFactory` cannot be read at compile time

2019-10-03 Thread Brett via Digitalmars-d-learn
auto r = replaceAll!((C) { return "X"; } )(s, regex(`Y`)); Error: static variable `thompsonFactory` cannot be read at compile time

Regex driving me nuts

2019-06-17 Thread Bart via Digitalmars-d-learn
Error: static variable `thompsonFactory` cannot be read at compile time, Trying to regex an import file. Also I have a group (...)* and it always fails or matches only one but if I do (...)(...)(...) it matches all 3(fails if more or less of course. ... is the regex). Also when I ignore a

splitter and matcher combined regex

2019-06-16 Thread Amex via Digitalmars-d-learn
Having to split and match seems slow(50%). Surely the regex splitter and matcher can be combined? Sometimes we just need to extract out and remove information simultaneously. I propose a new function called extractor that returns the matchAll and splitter's results but is optimized.

Re: Poor regex performance?

2019-04-04 Thread Jon Degenhardt via Digitalmars-d-learn
On Thursday, 4 April 2019 at 10:31:43 UTC, Julian wrote: On Thursday, 4 April 2019 at 09:57:26 UTC, rikki cattermole wrote: If you need performance use ldc not dmd (assumed). LLVM has many factors better code optimizes than dmd does. Thanks! I already had dmd installed from a brief look at D

Re: Poor regex performance?

2019-04-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Apr 04, 2019 at 09:53:06AM +, Julian via Digitalmars-d-learn wrote: [...] > auto re = ctRegex!(r"(?:\S+ ){3,4}<= ([^@]+@(\S+))"); [...] ctRegex is a crock; use regex() instead and it might actually work better. T -- Stop staring at me like that! It's

Re: Poor regex performance?

2019-04-04 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 4 April 2019 at 10:31:43 UTC, Julian wrote: On Thursday, 4 April 2019 at 09:57:26 UTC, rikki cattermole wrote: If you need performance use ldc not dmd (assumed). LLVM has many factors better code optimizes than dmd does. Thanks! I already had dmd installed from a brief look at D

Re: Poor regex performance?

2019-04-04 Thread Julian via Digitalmars-d-learn
On Thursday, 4 April 2019 at 09:57:26 UTC, rikki cattermole wrote: If you need performance use ldc not dmd (assumed). LLVM has many factors better code optimizes than dmd does. Thanks! I already had dmd installed from a brief look at D a long time ago, so I missed the details at https://dlang

Re: Poor regex performance?

2019-04-04 Thread XavierAP via Digitalmars-d-learn
On Thursday, 4 April 2019 at 09:53:06 UTC, Julian wrote: Relatedly, how can I add custom compiler flags to rdmd, in a D script? For example, -L-lpcre Configuration variable "DFLAGS". On Windows you can specify it in the sc.ini file. On Linux: https://dlang.org/dmd-linux.html

Re: Poor regex performance?

2019-04-04 Thread rikki cattermole via Digitalmars-d-learn
If you need performance use ldc not dmd (assumed). LLVM has many factors better code optimizes than dmd does.

Poor regex performance?

2019-04-04 Thread Julian via Digitalmars-d-learn
The following code, that just runs a regex against a large exim log to report on top senders, is 140 times slower than similar C code using PCRE, when compiled with just -O. With a bunch of other flags I got it down to only 13x slower than C code that's using libc regcomp/regexec. i

Re: Redundant "g" flag for regex?

2018-06-23 Thread biocyberman via Digitalmars-d-learn
On Saturday, 23 June 2018 at 13:45:32 UTC, Basile B. wrote: On Saturday, 23 June 2018 at 12:17:08 UTC, biocyberman wrote: I get the same output with or without "g" flag at line 6: https://run.dlang.io/is/9n7iz6 So I don't understand when I have to use "g" flag. My

Re: Redundant "g" flag for regex?

2018-06-23 Thread Basile B. via Digitalmars-d-learn
On Saturday, 23 June 2018 at 12:17:08 UTC, biocyberman wrote: I get the same output with or without "g" flag at line 6: https://run.dlang.io/is/9n7iz6 So I don't understand when I have to use "g" flag. My bet is that Regex results in D are lazy so "g"

Re: why explicitly use "flags" in regex does not work?

2018-06-23 Thread Basile B. via Digitalmars-d-learn
On Saturday, 23 June 2018 at 12:50:17 UTC, biocyberman wrote: On Saturday, 23 June 2018 at 12:20:10 UTC, biocyberman wrote: I got "Error: undefined identifier flags" in here: https://run.dlang.io/is/wquscz Removing "flags =" works. I kinda found an answer. It's a bit of a surprise anyway:

Re: why explicitly use "flags" in regex does not work?

2018-06-23 Thread biocyberman via Digitalmars-d-learn
On Saturday, 23 June 2018 at 12:20:10 UTC, biocyberman wrote: I got "Error: undefined identifier flags" in here: https://run.dlang.io/is/wquscz Removing "flags =" works. I kinda found an answer. It's a bit of a surprise anyway: https://forum.dlang.org/thread/wokfqqbexazcguffw...@forum.dlang

why explicitly use "flags" in regex does not work?

2018-06-23 Thread biocyberman via Digitalmars-d-learn
I got "Error: undefined identifier flags" in here: https://run.dlang.io/is/wquscz Removing "flags =" works.

Redundant "g" flag for regex?

2018-06-23 Thread biocyberman via Digitalmars-d-learn
I get the same output with or without "g" flag at line 6: https://run.dlang.io/is/9n7iz6 So I don't understand when I have to use "g" flag.

Re: forcing tabs in regex

2018-02-27 Thread Dmitry Olshansky via Digitalmars-d-learn
On Wednesday, 28 February 2018 at 05:09:03 UTC, psychoticRabbit wrote: On Wednesday, 28 February 2018 at 01:06:30 UTC, dark777 wrote: Regex validates years bisexto and not bisextos in format: const std::regex pattern(R"(^(?:(?:(0?[1-9]|1\d|2[0-8])([-/.])(0?[1-9]|1[0-2]|[Jj](?:an|u[nl])|

Re: forcing tabs in regex

2018-02-27 Thread psychoticRabbit via Digitalmars-d-learn
On Wednesday, 28 February 2018 at 01:06:30 UTC, dark777 wrote: Regex validates years bisexto and not bisextos in format: const std::regex pattern(R"(^(?:(?:(0?[1-9]|1\d|2[0-8])([-/.])(0?[1-9]|1[0-2]|[Jj](?:an|u[nl])|[Mm]a[ry]|[Aa](?:pr|ug)|[Ss]ep|[Oo]ct|[Nn]ov|[Dd]ec|[Ff]eb)|(29|30)([-/

forcing tabs in regex

2018-02-27 Thread dark777 via Digitalmars-d-learn
Regex validates years bisexto and not bisextos in format: const std::regex pattern(R"(^(?:(?:(0?[1-9]|1\d|2[0-8])([-/.])(0?[1-9]|1[0-2]|[Jj](?:an|u[nl])|[Mm]a[ry]|[Aa](?:pr|ug)|[Ss]ep|[Oo]ct|[Nn]ov|[Dd]ec|[Ff]eb)|(29|30)([-/.])(0?[13-9]|1[0-2]|[Jj](?:an|u[nl])|[Mm]a[ry]|[Aa](?:pr|ug)|[Ss]e

Re: Convert user input string to Regex

2017-09-16 Thread Ky-Anh Huynh via Digitalmars-d-learn
On Saturday, 16 September 2017 at 03:23:14 UTC, Adam D. Ruppe wrote: On Saturday, 16 September 2017 at 03:18:31 UTC, Ky-Anh Huynh wrote: Is there a way to transform user input string to a regular expression? For example, I want to write a `grep`-like program import std.regex; auto re = regex

Re: Convert user input string to Regex

2017-09-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 16 September 2017 at 03:18:31 UTC, Ky-Anh Huynh wrote: Is there a way to transform user input string to a regular expression? For example, I want to write a `grep`-like program import std.regex; auto re = regex(user_pattern, user_flags); You'll probably want to split it o

Convert user input string to Regex

2017-09-15 Thread Ky-Anh Huynh via Digitalmars-d-learn
Hi, Is there a way to transform user input string to a regular expression? For example, I want to write a `grep`-like program ``` mygrep -E '/pattern/i' file.txt ``` and here the user's parameter `/pattern/i` would be converted to a Regex object. Fyi, in Ruby, `to_regexp`

Trouble with regex backreferencing

2017-06-12 Thread Murp via Digitalmars-d-learn
I was working around with regex trying to match certain patterns of repeating patterns before and after a space and I came across some unexpected behavior. writeln("ABC ABC CBA".replaceAll(regex(r"([A-Z]) ([A-Z])"), "D")); //ABDBDBA //Makes se

Re: Regex multiple matches

2017-04-13 Thread rikki cattermole via Digitalmars-d-learn
On 14/04/2017 3:54 AM, Jethro wrote: using the rule (?Pregex) e.g., (?P\w*)* how do we get at all the matches, e.g., Joe Bob Buddy? When I access the results captures they are are not arrays and I only ever get the first match even when I'm using matchAll. Pseudo code: foreach(result; match

Regex multiple matches

2017-04-13 Thread Jethro via Digitalmars-d-learn
using the rule (?Pregex) e.g., (?P\w*)* how do we get at all the matches, e.g., Joe Bob Buddy? When I access the results captures they are are not arrays and I only ever get the first match even when I'm using matchAll.

How do I get names of regex captures during iteration? Populate AAs with captures?

2017-02-28 Thread Chad Joan via Digitalmars-d-learn
an associative array (AA) with all named captures that successfully matched during a regex match (and none of the captures that failed). I was wondering what the best way to do this might be. Thanks! Please see comments in the below program for details and my current progress: void main() {

Regex replace followed by number.

2016-06-01 Thread Taylor Hillegeist via Digitalmars-d-learn
So I have ran into an issue where I want to replace a string with regex. but i cant figure out how to replace items followed by a number. i use "$1001" to do paste first match but this thinks I'm trying using match 1001 but if i try ${1}001 it gives me an error saying that it

Re: regex - match/matchAll and bmatch - different output

2016-01-02 Thread Ivan Kazmenko via Digitalmars-d-learn
ch does not properly support the particular backreference but bmatch does, the bug is in using the incorrect one to handle a pattern. At any rate, wrong result with a 8-character pattern produces a "regex don't work" impression, and I hope something can be done about it.

Re: Why can't a Regex object be immutable?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
cym13 wrote: > Is it that you > can't make an immutable regex()? In that case it is a > runtime-related issue and those variables just have to be > mutable. Or is it that you want to be able to use an immutable or > const regex (be it from regex() or ctRegex!()) with matchAl

Re: Why can't a Regex object be immutable?

2016-01-01 Thread cym13 via Digitalmars-d-learn
at you meant by "the same error" is the « Error: template std.regex.matchAll cannot deduce function from argument types !()(string, const(StaticRegex!char)) » one. But that error has nothing to do with the first one (« Error: cannot implicitly convert expression (regex("\\d+", &q

Re: Why can't a Regex object be immutable?

2016-01-01 Thread cym13 via Digitalmars-d-learn
On Saturday, 2 January 2016 at 02:39:36 UTC, Shriramana Sharma wrote: Aw come on. The immutability of the variable is *after* it has been created at runtime. Sure, but still... > you'll find that using ctRegex() instead will allow you to declare it immutable for example. I didn't look at the

Re: Why can't a Regex object be immutable?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
cym13 wrote: > I think it's because regex() only compiles the regex at runtime > so it needs to be modified later ; Aw come on. The immutability of the variable is *after* it has been created at runtime. > > you'll find that using > ctRegex() instead will allow you to

Re: Why can't a Regex object be immutable?

2016-01-01 Thread cym13 via Digitalmars-d-learn
On Saturday, 2 January 2016 at 02:03:13 UTC, Shriramana Sharma wrote: Shriramana Sharma wrote: Why is it impossible for a Regex object to be `immutable`? I find that I can't declare it as `const` either... This is most curious! I think it's because regex() only compiles th

Why can't a Regex object be immutable?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
Hello. With this code: import std.stdio, std.regex; void main() { immutable numbers = regex(r"\d+"); foreach (match; "a1b2c3d4e5".matchAll(numbers)) writeln(match[0]); } compiling gives the error: (4): Error: cannot implicitly convert expression (regex(&

Re: Why can't a Regex object be immutable?

2016-01-01 Thread Shriramana Sharma via Digitalmars-d-learn
Shriramana Sharma wrote: > Why is it impossible for a Regex object to be > `immutable`? I find that I can't declare it as `const` either... This is most curious! -- Shriramana Sharma, Penguin #395953

Re: regex - match/matchAll and bmatch - different output

2016-01-01 Thread anonymous via Digitalmars-d-learn
On 30.12.2015 12:06, Ivan Kazmenko wrote: import std.regex, std.stdio; void main () { writeln (bmatch ("abab", r"(..).*\1")); // [["abab", "ab"]] writeln (match("abab", r"(..).*\1")); // [["abab", "ab"]] writeln (matchAll ("abab", r"(..).*\1")); // [["abab", "ab"]]

Re: regex - match/matchAll and bmatch - different output

2015-12-31 Thread Ivan Kazmenko via Digitalmars-d-learn
On Wednesday, 30 December 2015 at 11:06:55 UTC, Ivan Kazmenko wrote: ... As you can see, bmatch (usage discouraged in the docs) gives me the result I want, but match (also discouraged) and matchAll (way to go) don't. Am I misusing matchAll, or is this a bug? Reported as https://issues.dlan

regex - match/matchAll and bmatch - different output

2015-12-30 Thread Ivan Kazmenko via Digitalmars-d-learn
Hi, While solving Advent of Code problems for fun (already discussed in the forum: http://forum.dlang.org/post/cwdkmblukzptsrsrv...@forum.dlang.org), I ran into an issue. I wanted to test for the pattern "two consecutive characters, arbitrary sequence, the same two consecutive characters". Sa

Re: How to replace inside regex?

2015-12-17 Thread Ali Çehreli via Digitalmars-d-learn
llowing style works for me: import std.stdio; import std.string; import std.regex; import std.array; void main() { auto data = [ "abc=1", "def=2", "xyz=3" ]; /* Matches patterns like a=1 * * Note the parentheses around the two pattern

How to replace inside regex?

2015-12-17 Thread Suliman via Digitalmars-d-learn
I can't understand how to replace in regex. I have got next task: find all commas in strings inside quotes and replace them. foo, bar, "hello, user", baz I wrote next regexp that find part that include commas inside the quotes: auto partWithComma = matchAll(line, r); but I c

Re: failing regex

2015-11-23 Thread Rikki Cattermole via Digitalmars-d-learn
On 23/11/15 9:30 PM, yawniek wrote: regex from https://github.com/ua-parser/uap-core/blob/master/regexes.yaml#L38 seems to work in other languages, not so in D: auto r2 = r"(?:\/[A-Za-z0-9\.]+)? *([A-Za-z0-9 _\!\[\]:]*(?:[Aa]rchiver|[Ii]ndexer|[Ss]craper|[Bb]ot|[Ss]pider|[Cc]rawl[a-z]*)

Re: regex format string problem

2015-11-23 Thread Rikki Cattermole via Digitalmars-d-learn
x27;ll increase performance significantly. that was my plan. Reguarding regex, if you want a named sub part use: (?[a-z]*) Where [a-z]* is just an example. I would recommend you learning how input ranges work. They are used with how to get the matches out, e.g. auto rgx = ctRegex!`([a-z])[123]`

failing regex

2015-11-23 Thread yawniek via Digitalmars-d-learn
regex from https://github.com/ua-parser/uap-core/blob/master/regexes.yaml#L38 seems to work in other languages, not so in D: auto r2 = r"(?:\/[A-Za-z0-9\.]+)? *([A-Za-z0-9 _\!\[\]:]*(?:[Aa]rchiver|[Ii]ndexer|[Ss]craper|[Bb]ot|[Ss]pider|[Cc]rawl[a-z]*)) (\d+)(?:\.(\d+)(?:\.(\d+))?)?&q

Re: regex format string problem

2015-11-23 Thread yawniek via Digitalmars-d-learn
e significantly. that was my plan. Reguarding regex, if you want a named sub part use: (?[a-z]*) Where [a-z]* is just an example. I would recommend you learning how input ranges work. They are used with how to get the matches out, e.g. auto rgx = ctRegex!`([a-z])[123]`; foreach(match; r

Re: regex format string problem

2015-11-22 Thread Rikki Cattermole via Digitalmars-d-learn
significantly. Reguarding regex, if you want a named sub part use: (?[a-z]*) Where [a-z]* is just an example. I would recommend you learning how input ranges work. They are used with how to get the matches out, e.g. auto rgx = ctRegex!`([a-z])[123]`; foreach(match; rgx.matchAll("b3")

regex format string problem

2015-11-22 Thread yawniek via Digitalmars-d-learn
hi! how can i format a string with captures from a regular expression? basically make this pass: https://gist.github.com/f17647fb2f8ff2261d42 context: i'm trying to write a implementation for https://github.com/ua-parser where the regular expression as well as the format strings are given.

Re: Error in trying to use an inout(char)[] with a regex

2015-10-16 Thread Shriramana Sharma via Digitalmars-d-learn
Ali Çehreli wrote: > Meanwhile, can you try the following template which works at least for > the reduced code: > > import std.range; > > auto foo(S)(S text) > if (isSomeString!S) { > import std.regex; > static auto inlineRE = ctRegex!`\$\(ta (.*?)\)`; > return text.replaceAll!(m => textAttr(m[1

Re: Error in trying to use an inout(char)[] with a regex

2015-10-16 Thread Ali Çehreli via Digitalmars-d-learn
On 10/16/2015 07:06 PM, Shriramana Sharma wrote: > /usr/include/dmd/phobos/std/regex/package.d(557): Error: variable > std.regex.RegexMatch!(inout(char)[], BacktrackingMatcher).RegexMatch._input > only parameters or stack based variables can be inout Reduced: inout(char)[] foo(i

Error in trying to use an inout(char)[] with a regex

2015-10-16 Thread Shriramana Sharma via Digitalmars-d-learn
stdio; if (args.length == 1) return; alias ta = textAttr; writeln(ta(args[1 .. $]), "text1", ta("u g /w"), "text2", ta("off")); } Now upon trying to compile this I'm getting the errors: $ dmd inout_test.d /usr/include/dmd/phobos/std/regex/package

Re: Regex start/end position of match?

2015-10-01 Thread Gerald via Digitalmars-d-learn
Thanks Adam, that was the hint I needed. For a given RegexMatch the pre().length() is essentially equivalent to the start position and taking pre().length + hit.length() gives the end position so I think this should be OK for my needs.

Re: Regex start/end position of match?

2015-10-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 1 October 2015 at 03:29:29 UTC, Gerald wrote: I'm stuck though on how to get the start/end index of a match? I couldn't find one either so I did the pre/post/hit things broken up. Take a look at this little program I wrote: http://arsdnet.net/dcode/replacer/ All the files it n

Regex start/end position of match?

2015-09-30 Thread Gerald via Digitalmars-d-learn
I'm using the std.regex API as part of Linux GUI grep utility I'm trying to create. I've got the GUI going fine using gtkd, the code to iterate over files (wow that was succinct in D, very impressive!), and getting matches via regex using the matchAll function. I'm stuck

Re: Regex-Fu

2015-05-25 Thread Chris via Digitalmars-d-learn
On Monday, 25 May 2015 at 11:20:46 UTC, novice2 wrote: I cannot get the longest possible it match longest for first group ([a-z]+) try ^([a-z]+?)(hula|ula)$ Namespace, novice2: Ah, I see. The problem was with the first group that was too greedy, not with the second. I was focusing on the l

Re: Regex-Fu

2015-05-25 Thread novice2 via Digitalmars-d-learn
I cannot get the longest possible it match longest for first group ([a-z]+) try ^([a-z]+?)(hula|ula)$

Re: Regex-Fu

2015-05-25 Thread Namespace via Digitalmars-d-learn
On Monday, 25 May 2015 at 11:11:50 UTC, Chris wrote: I'm a bit at a loss here. I cannot get the longest possible match. I tried several versions with eager operators and stuff, but D's regex engine(s) always seem to return the shortest match. Is there something embarrassingly

Regex-Fu

2015-05-25 Thread Chris via Digitalmars-d-learn
I'm a bit at a loss here. I cannot get the longest possible match. I tried several versions with eager operators and stuff, but D's regex engine(s) always seem to return the shortest match. Is there something embarrassingly simple I'm missing? void main() { import st

Re: Degenerate Regex Case

2015-04-26 Thread Guillaume via Digitalmars-d-learn
On Saturday, 25 April 2015 at 09:30:55 UTC, Dmitry Olshansky wrote: A quick investigation shows that it gets stuck at the end of pattern compilation stage. The problem is that as a last pass D's regex goes to optimize the pattern to construct simple bit-scanning engine as approximatio

Re: Degenerate Regex Case

2015-04-25 Thread Dmitry Olshansky via Digitalmars-d-learn
On Friday, 24 April 2015 at 18:28:16 UTC, Guillaume wrote: Hello, I'm trying to make a regex comparison with D, based off of this article: https://swtch.com/~rsc/regexp/regexp1.html I've written my code like so: import std.stdio, std.regex; void main(string argv[]) { strin

Re: Degenerate Regex Case

2015-04-24 Thread TheFlyingFiddle via Digitalmars-d-learn
On Friday, 24 April 2015 at 18:28:16 UTC, Guillaume wrote: Hello, I'm trying to make a regex comparison with D, based off of this article: https://swtch.com/~rsc/regexp/regexp1.html I've written my code like so: import std.stdio, std.regex; void main(string argv[]) { strin

Degenerate Regex Case

2015-04-24 Thread Guillaume via Digitalmars-d-learn
Hello, I'm trying to make a regex comparison with D, based off of this article: https://swtch.com/~rsc/regexp/regexp1.html I've written my code like so: import std.stdio, std.regex; void main(string argv[]) { string m = argv[1]; auto p = ctRegex!("a?a?a?a?a?a?a?a?a?

Re: regex on binary data

2014-12-31 Thread ketmar via Digitalmars-d-learn
On Wed, 31 Dec 2014 15:36:16 + Darrell via Digitalmars-d-learn wrote: > So far attempts to run regex on binary data causes > "Invalid UTF-8 sequence". > > Attempts to pass ubyte also didn't work out. current regex engine assumes that you are using UTF-8 encode

Re: regex on binary data

2014-12-31 Thread Tobias Pankrath via Digitalmars-d-learn
On Wednesday, 31 December 2014 at 15:36:19 UTC, Darrell wrote: So far attempts to run regex on binary data causes "Invalid UTF-8 sequence". Attempts to pass ubyte also didn't work out. I doubt using anything except (d,w)string is supported or possible.

regex on binary data

2014-12-31 Thread Darrell via Digitalmars-d-learn
So far attempts to run regex on binary data causes "Invalid UTF-8 sequence". Attempts to pass ubyte also didn't work out.

  1   2   3   >