firasdib / Regex101

This repository is currently only used for issue tracking for www.regex101.com
3.24k stars 199 forks source link

C# flavor #156

Closed shiralizadeh closed 2 years ago

shiralizadeh commented 9 years ago

Hi regex101, Can you add C# to your Flavor section? If you want I can help you for this.

Thanks, Shiralizadeh

3F commented 9 years ago

@shiralizadeh :( see #124

You will need to use a PCRE-compatible syntax. https://github.com/firasdib/Regex101/issues/124#issuecomment-55915837

+1 also need !

firasdib commented 9 years ago

As with all the other requests for more flavors, there's not much I can do right now.

MulleDK19 commented 9 years ago

+1 It's sad I can't use patterns like "(?<=(.*?))HELLOWORLD", while .NET supports this.

.NET still has the best RegEx engine.

MNF commented 8 years ago

I needed to use named capturing groups and .Net has different syntax for it. I had to use http://regexstorm.net/tester and it is not comparable-RegEx101 is significantly user friendlier. Having .Net flavor will be very useful.

JohnLouderback commented 7 years ago

This would be a very welcomed feature! šŸ‘

AnderssonPeter commented 7 years ago

What is hindering you form adding support for the .net regex engine? You have multiple options for running .net under non windows environments if thatĀ“s the problem.

TWiStErRob commented 7 years ago

@AnderssonPeter engines are currently all client-side, so only JS would be considered IMO. @firasdib https://github.com/bridgedotnet/Bridge/tree/master/Bridge/Resources/Text/RegularExpressions package looks good. With a bit of work (namely implementing Bridge.define) it may be useful.

laschon commented 7 years ago

The variable-width lookbehind support in .NET is very useful and not easy to imitate using PCRE.

Doqnach commented 7 years ago

Has the variable width look-behind been made easier to implement maybe, now that python regex also supports it?

bjorndavis commented 7 years ago

Would love a C# flavor - this is the best RegEx site I've found, but unfortunately I can't always use it with C#.

DazEdword commented 6 years ago

I concur here, this is clearly my favourite Regex online tool and would love to have full C# support. Thanks for your hard work!

Shane32 commented 6 years ago

If it at least could support copy/paste to c# it would be extremely helpful

mavericksevmont commented 6 years ago

+1, Best regex site, would be amazing if it had the C# regex flavor!

Kaon68 commented 6 years ago

I use regexhero for .Net, but an online version would be great. +1 for a .Net (C#) flavor :)

OmrSi commented 5 years ago

Ah. +1

joshuaquiz commented 5 years ago

+1 referencing named groups is shown in here as \g but for .NET it is \k. There are other small differences that it would be handy to be able to know/learn/lookup.

Doqnach commented 5 years ago

There are other small differences that it would be handy to be able to know/learn/lookup.

This resource can help you with that: https://www.regular-expressions.info/dotnet.html

chucker commented 5 years ago

engines are currently all client-side, so only JS would be considered IMO.

With WebAssembly (and Mono-Wasm in particular), this theoretically changes. This is clearly in early stages and a lot of overhead, but might be something to be considered for the long run.

firasdib commented 5 years ago

@chucker If you can create a POC with wasm, I'd be more than happy to implement it.

lfr commented 5 years ago

@chucker the ball is on your side buddy šŸ˜¬

chucker commented 5 years ago

Iā€™ll see when I can get around to it.

firasdib commented 5 years ago

@chucker I have a few days off, if you're up for it, we can work on this together.

chucker commented 5 years ago

If you can create a POC with wasm

How far does this POC need to go? Are there APIs of sorts that I can implement?

firasdib commented 5 years ago

@chucker For the POC I just want a hello world executing a simple regex, it can even be hard coded. As long as we can see it works.

chucker commented 5 years ago

@firasdib ok, got caught up in some other stuff, but https://github.com/chucker/monowasm-regex-poc is exactly that. Check out the readme.

firasdib commented 5 years ago

@chucker Thank you very much. If you have time, please drop by IRC so we can have a chat about how to best integrate the .NET engine into the website.

Shane32 commented 5 years ago

I saw a note earlier about the mono implementation of regex having issues. Just wanted to point out that according to the mono team, they consider their own implementation of regex to be "buggy, poorly maintained or a source of problems", and plan to entirely replace their code with the source code from .net core. So given a choice to develop with mono/webassembly or .net core/webassembly, I'd suggest the .net core version.

Source: https://www.mono-project.com/docs/about-mono/dotnet-integration/

Shane32 commented 5 years ago

.Net Core in the browser is in preview by Microsoft (the Blazor project) planned to be officially released after .Net Core 3.0 later this year.

https://dotnet.microsoft.com/apps/aspnet/web-apps/client

https://devblogs.microsoft.com/aspnet/blazor-now-in-official-preview/

pruiz commented 5 years ago

I've been a hardcore user of mono's regex, and a regex as simple as the one being mentioned here, I highly doubt will fail. :?

On Mon, May 27, 2019 at 2:41 AM Shane32 notifications@github.com wrote:

I saw a note earlier about the mono implementation of regex having issues. Just wanted to point out that according to the mono team, they consider their own implementation of regex to be "buggy, poorly maintained or a source of problems", and plan to entirely replace their code with the source code from .net core. So given a choice to develop with mono/webassembly or .net core/webassembly, I'd suggest the .net core version.

Source: https://www.mono-project.com/docs/about-mono/dotnet-integration/

ā€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/firasdib/Regex101/issues/156?email_source=notifications&email_token=AABOV6LLY4H6MRFOMWLGYNLPXMU5HA5CNFSM4AWGEDY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWIQX2Q#issuecomment-496045034, or mute the thread https://github.com/notifications/unsubscribe-auth/AABOV6ISNZRRXFDQHWZYGLLPXMU5HANCNFSM4AWGEDYQ .

chucker commented 5 years ago

So given a choice to develop with mono/webassembly or .net core/webassembly, I'd suggest the .net core version.

The problem is CoreRT is not as far along.

As for the original comment, Iā€™m not sure why it was deleted, but it seemed to be a simple coding error, setting regex options and then not actually using them.

the Blazor project

Blazor is an SPA framework like Angular or React. The underlying WebAssembly integration comes from Mono and is what my PoC builds upon.

firasdib commented 5 years ago

Sorry for the false alarm friends. I had made a typo in the code, and was too tired to notice it. I deleted the comment to not confuse others, but it seems everyone got an email notification :-)

Shane32 commented 5 years ago

Personally, I'd be happy if the site simply converted the C# escaping into javascript escaping and ran the regex string within javascript, so you can copy and paste between the website and C#. Maybe throw an error for known tokens that are unsupported in the C# flavor. Anything more would be a bonus (like using mono/.net to actually test the regex string with).

firasdib commented 5 years ago

Could someone help me compile a list of the differences between the .NET engine and say JS and PCRE?

This will aid a lot in writing the regex parser for the language, and save me a lot of trial and error.

Shane32 commented 5 years ago

This site has a pretty well-document list of token differences between any flavor, including Javascript and C#: https://www.regular-expressions.info/refcharacters.html

firasdib commented 5 years ago

Status update

The good: .NET is now almost entirely integrated into the website. I need to finish adding substitution and quickref, and fixing minor bugs in the parser. Otherwise things are looking very good.

The bad: when compiling mono, it outputs 23 dlls that are required to be downloaded (along with the js+wasm code), which totals to around 16mb. This is far from ideal, and I'm not sure what can be done to reduce the file sizes and/or the amount of dlls.

Any ideas?

TWiStErRob commented 5 years ago

I know it's Android, but could help you: https://stackoverflow.com/a/13352758/253468 ProGuard is tree-shaking and minifier for Java. I guess you need the equivalent for .NET assemblies which above SO answer seems to provide.

firasdib commented 5 years ago

@TWiStErRob Tree shaking might definitely help. No idea how that works here though. I also believe I need to use AOT compilation to get rid of all the dlls, but the size of the resulting file might be the same.

@chucker Do you have any idea?

chucker commented 5 years ago

Any ideas?

Yes ā€” you want to run the linker. https://github.com/dotnet/core/blob/master/samples/linker-instructions.md

This will more aggressively do dead code elimination and should get you down to about 2 MiB. In addition, if you want to reduce files, you may be able to combine this with ILMerge, but Iā€™m not sure if that will work in this scenario.

As for AOT, thatā€™s also an option (though primarily for performance reasons), but sort of experimental at this point (for example, Blazor doesnā€™t offer it out of the box yet).

firasdib commented 5 years ago

@chucker Thanks for the link. I'll see if I can manage to get that working. If you have some time over, I'd love the help.

As for performance, this is the statistics I've managed to gather so far:

Running the regex /./g on a string of 10,000 characters:

So its definitely not fast, but it might be better after I get the linker working.

firasdib commented 5 years ago

@chucker For a novice like me, this wasn't all too straight forward. I don't know how to proceed from here. I'm running OSX, if that matters.

The .NET engine is integrated into the website now, and this basic POC works just fine. However, I need help with improving the performance of the library and reducing its size. I have not been able to do it myself yet.

If anyone can help, that'd be greatly appreciated. The faster we can get that sorted, the faster you guys can start using .NET on regex101.com :-)

firasdib commented 5 years ago

Bump. Anybody who can help? The release of .NET hinges only on this right now.

@chucker You seem quite knowledgable. Do you know how I can create an optimized version of the library?

chucker commented 5 years ago

I saw your comment but canā€™t devote time at this point. Maybe in a week or two.

Reducing footprint is doable. Improving performance may be best to revisit in another year or so, when Monoā€™s AOT efforts are more stable.

firasdib commented 5 years ago

@chucker I'd be happy with just reducing the footprint, as a first step. Any help you can provide is much appreciated. Feel free to message me at any time.

firasdib commented 5 years ago

@chucker Have you had time to get around to it?

chucker commented 5 years ago

Not yet, sorry. Hopefully this weekend.

L4ZZA commented 5 years ago

Not having .NET regex engine on the best online regex testing online platform feels just like a joke. Please we're waiting for it!

P.S. it doesn't have to be the .NET engine, it just needs to behave like such reference link

firasdib commented 5 years ago

@L4ZZA I'll be working on it some more in the coming weeks.

I'm still hoping that @chucker will have some time to look into it, but if not, I might still release the large version of the library and evaluate how it goes.

Code-DJ commented 5 years ago

@firasdib see if this helps https://www.hanselman.com/blog/ExperimentalReducingTheSizeOfNETCoreApplicationsWithMonosLinker.aspx

chucker commented 5 years ago

I'm still hoping that @chucker will have some time to look into it

Can't make any promises, but would still love to see this.

firasdib commented 5 years ago

I've been trying to build the mono repo according to the documentation here (https://github.com/mono/mono/tree/master/sdks/wasm) and experiment with the linker, but so far I haven't been able to build it. I keep getting errors related to OSX, even though I am running this on Linux (such as Xcode not being installed).

Not sure what to do with this. I could release the current version I have locally, but that has 15mb dll-dependencies that each user will have to download, which are quite suboptimal (both from performance, but also the servers bandwidth limitations).

@chucker Any chance we can have a short chat some day and try to work this out?