Daniel Gustafsson
Daniel Gustafsson

Reputation: 1817

.net vs JS regex issue

I have a pretty complicated regex that i have finally managed to work in JS

  ^\s*((\(\s*([^]+\"|[@#a-zA-Z0-9_-åäöøæüßÅÄÖØÆÜ\-]+){1}(\s{1,}OR\s{1,}(\"[^\"]+\"|[@#a-zA-Z0-9_-åäöøæüßÅÄÖØÆÜ\-]+))*\s*\)))((\s{1,}(AND|NEAR(\/(100|[0-9][0-9]?)(?=\s))?)\s{1,})(\(\s*(\"[^\"]+\"|[@#a-zA-Z0-9_-åäöøæüßÅÄÖØÆÜ\-]+){1}(\s{1,}OR\s{1,}(\"[^\"]+\"|[@#a-zA-Z0-9_-åäöøæüßÅÄÖØÆÜ\-]+))*\s*\)))?(\s{1,}(AND\s{1,}NOT)\s{1,}(\(\s*(\"[^\"]+\"|[@#a-zA-Z0-9_-åäöøæüßÅÄÖØÆÜ\-]+){1}(\s{1,}OR\s{1,}(\"[^\"]+\"|[@#a-zA-Z0-9_-åäöøæüßÅÄÖØÆÜ\-]+))*\s*\)))?(?=(\s*\))?(\;)?\s*$)

with the text: (TITLE: "asdasd")

But when i send the text to my C# backend and uses the same regex it failes. Is there anywhere i can find out why it failes? I have tried some different online tools but none of them explain why it doesn't work.

I just need to be pointed in the right direction here since i'm pretty new working with regex. Thanks!

Upvotes: 0

Views: 53

Answers (1)

Sebastian Proske
Sebastian Proske

Reputation: 8413

The issue is [^] that you use in your expression. In JS syntax, it matches any character including newlines. In .net syntax, this is not a valid regex token.

You should be able to use [\s\S] as a replacement in both, matching any character including newlines.

Upvotes: 1

Related Questions