How can I attach two regular expressions to one?

I have two regular expressions that I need to combine into one since I use RegularExpressionAttribute in ASP.NET and it does not allow multiple instances.

How can I attach the following two regular expressions to one?

.* ?@ (?!.*?\.\.)[^@]+$ [\x00-\x7F] 

the first checks that there are no two consecutive points in the domain part of the message, and the second regular expression checks that all ascii characters

I thought it would be as simple as combining them together as (.* ?@ (?!.*?\.\.)[^@]+$)([\x00-\x7F]) , but this does not work.

Here is the link to the previous post related to this issue

EDIT . I decorate the string property of my view model using the reglarexpression attribute, and this turns into javascript using unobtrusive, so it should check for javascript usage. I did not mention this in my initial post

+6
source share
2 answers

You can use:

 ^[\x00-\x7F] +?@ (?!.*?\.\.)(?=[\x01-\x7F]+$)[^@]+$ 
+3
source

You can just use this regex

 ^[\x00-\x7F-[@]]* ?@ (?!.*?\.\.)[\x00-\x7F-[@]]+$ 

Or, if you want to match at least 1 character before @ :

 ^[\x00-\x7F] +@ (?!.*?\.\.)[\x00-\x7F-[@]]+$ 

Remember that [\x00-\x7F] also includes the @ character. In C # regex, we can subtract this from the range using -[@] inside the character class.

And you don’t need anchors, since you use this in RegularExpressionAttribute , I suppose.

Here is the daemon on regexstorm.net , delete the second @ and you will have a match.

+3
source

Source: https://habr.com/ru/post/985756/


All Articles