digitalmars.D.learn - Where do you test syntax of D regexp online?
- Suliman (32/32) Mar 09 2017 I wrote two regexp:
- rikki cattermole (8/40) Mar 09 2017 I would use dpaste and write a quick script but here is where I think
- Suliman (2/9) Mar 09 2017 Sorry, but what regexp are you talking? There is nothing like:
- rikki cattermole (3/17) Mar 09 2017 Yes there was:
- Suliman (2/22) Mar 09 2017 I still can't get it work in real code :(
- Suliman (5/5) Mar 09 2017 Adding "r" helped:
- Adam D. Ruppe (7/10) Mar 09 2017 That's just the writeln array formatter. The matchFirst function
- Suliman (7/18) Mar 09 2017 How should I write to file result without \r\n\ symbols?
- Adam D. Ruppe (5/9) Mar 09 2017 Just
- rikki cattermole (2/7) Mar 09 2017 \r\n is Windows new line characters.
I wrote two regexp: -------------------- auto inlineCodeBlock = regex("`(.*?)`"); // --> `(.*?)` auto bigCodeBlock = regex("/`{3}[\\s\\S]*?`{3}/g"); // --> `{3}[\s\S]*?`{3} -------------------- First for for selection inline code block. Second for multi-line: -------------------- #Header my header text my sub header text `foo inline code` ``` void foo() { writeln("ppp"); } ``` my sub 3 text `bar inline code` #Header2 my header2 text -------------------- It's work fine in online editor https://regex101.com/r/EC5WRu/1 (sic! \\s\\S double escaped in D code). But after compilation of code: auto x = content.matchFirst(bigCodeBlock); writeln(x); print: [] [] It's seems that D regexp work in another way. How can I test them?
Mar 09 2017
On 10/03/2017 3:50 AM, Suliman wrote:I wrote two regexp: -------------------- auto inlineCodeBlock = regex("`(.*?)`"); // --> `(.*?)` auto bigCodeBlock = regex("/`{3}[\\s\\S]*?`{3}/g"); // --> `{3}[\s\S]*?`{3} -------------------- First for for selection inline code block. Second for multi-line: -------------------- #Header my header text my sub header text `foo inline code` ``` void foo() { writeln("ppp"); } ``` my sub 3 text `bar inline code` #Header2 my header2 text -------------------- It's work fine in online editor https://regex101.com/r/EC5WRu/1 (sic! \\s\\S double escaped in D code). But after compilation of code: auto x = content.matchFirst(bigCodeBlock); writeln(x); print: [] [] It's seems that D regexp work in another way. How can I test them?I would use dpaste and write a quick script but here is where I think your problem is: regex("/.*/g") It should be: regex(".*", "g") As per[0].
Mar 09 2017
I would use dpaste and write a quick script but here is where I think your problem is: regex("/.*/g") It should be: regex(".*", "g") As per[0].Sorry, but what regexp are you talking? There is nothing like: `regex("/.*/g")` in my code...
Mar 09 2017
On 10/03/2017 4:17 AM, Suliman wrote:Yes there was: auto bigCodeBlock = regex("/`{3}[\\s\\S]*?`{3}/g");I would use dpaste and write a quick script but here is where I think your problem is: regex("/.*/g") It should be: regex(".*", "g") As per[0].Sorry, but what regexp are you talking? There is nothing like: `regex("/.*/g")` in my code...
Mar 09 2017
On Thursday, 9 March 2017 at 15:22:00 UTC, rikki cattermole wrote:On 10/03/2017 4:17 AM, Suliman wrote:I still can't get it work in real code :(Yes there was: auto bigCodeBlock = regex("/`{3}[\\s\\S]*?`{3}/g");I would use dpaste and write a quick script but here is where I think your problem is: regex("/.*/g") It should be: regex(".*", "g") As per[0].Sorry, but what regexp are you talking? There is nothing like: `regex("/.*/g")` in my code...
Mar 09 2017
Adding "r" helped: auto bigCodeBlock = regex(r"`{3}[\s\S]*?`{3}"); But now output is: [["```\r\nvoid foo()\r\n{\r\n\twriteln(\"ppp\");\r\n}\r\n```"]] But I do not \r\n\ symbols...
Mar 09 2017
On Thursday, 9 March 2017 at 16:14:28 UTC, Suliman wrote:But now output is: [["```\r\nvoid foo()\r\n{\r\n\twriteln(\"ppp\");\r\n}\r\n```"]] But I do not \r\n\ symbols...That's just the writeln array formatter. The matchFirst function returns an array of hits (that allows captures, btw you might need to use \( instead of ( to get the capture, god i hate regex) so writeln tries to print the whole array and that's how it does embedded newlines. So you have the correct result, just written strangely.
Mar 09 2017
On Thursday, 9 March 2017 at 16:23:23 UTC, Adam D. Ruppe wrote:On Thursday, 9 March 2017 at 16:14:28 UTC, Suliman wrote:How should I write to file result without \r\n\ symbols? auto x = content.matchFirst(bigCodeBlock); File f = File("foo.txt", "w"); f.write(x); foo.txt: ["```\r\nvoid foo()\r\n{\r\n\twriteln(\"ppp\");\r\n}\r\n```"]But now output is: [["```\r\nvoid foo()\r\n{\r\n\twriteln(\"ppp\");\r\n}\r\n```"]] But I do not \r\n\ symbols...That's just the writeln array formatter. The matchFirst function returns an array of hits (that allows captures, btw you might need to use \( instead of ( to get the capture, god i hate regex) so writeln tries to print the whole array and that's how it does embedded newlines. So you have the correct result, just written strangely.
Mar 09 2017
On Thursday, 9 March 2017 at 16:40:13 UTC, Suliman wrote:How should I write to file result without \r\n\ symbols? auto x = content.matchFirst(bigCodeBlock); File f = File("foo.txt", "w"); f.write(x);Just f.write(x[0]); to write out the whole hit instead of the collection of references.
Mar 09 2017
On Thursday, 9 March 2017 at 16:47:18 UTC, Adam D. Ruppe wrote:On Thursday, 9 March 2017 at 16:40:13 UTC, Suliman wrote:What can be wrong with this regexp? https://regex101.com/r/8e7nPL/3 it's crush D compiler, and I can't find out whyHow should I write to file result without \r\n\ symbols? auto x = content.matchFirst(bigCodeBlock); File f = File("foo.txt", "w"); f.write(x);Just f.write(x[0]); to write out the whole hit instead of the collection of references.
Mar 10 2017
On Friday, 10 March 2017 at 14:36:48 UTC, Suliman wrote:On Thursday, 9 March 2017 at 16:47:18 UTC, Adam D. Ruppe wrote:like: #header some text and some code ^ first matching #header2 some text2 and some code2 ^ second matchingOn Thursday, 9 March 2017 at 16:40:13 UTC, Suliman wrote:What can be wrong with this regexp? https://regex101.com/r/8e7nPL/3 it's crush D compiler, and I can't find out whyHow should I write to file result without \r\n\ symbols? auto x = content.matchFirst(bigCodeBlock); File f = File("foo.txt", "w"); f.write(x);Just f.write(x[0]); to write out the whole hit instead of the collection of references.
Mar 10 2017
On 10/03/2017 5:14 AM, Suliman wrote:Adding "r" helped: auto bigCodeBlock = regex(r"`{3}[\s\S]*?`{3}"); But now output is: [["```\r\nvoid foo()\r\n{\r\n\twriteln(\"ppp\");\r\n}\r\n```"]] But I do not \r\n\ symbols...\r\n is Windows new line characters.
Mar 09 2017