简体   繁体   中英

How to perform AND operator in a C# regex

I have two regular expressions that are being used for different purposes.

^(?:(?!(?:abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz|012|123|234|345|456|567|678|789|(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)'\'1{2})).)

This regex is for controlling that a string can't contain 3 consecutive characters like abc , 123

^['\'x20-\x7E]+$

And this regex is for controlling that a string can't contain non-english characters like ş , ü , ı , ğ ,...

I would like to combine these two rules. Both of them must be performed. I tried to add an AND operator to between them but & isn't allowed.

How can i do this? Are there any operator in regex substitutes of & ? If there aren't, How can i do this same job by different ways?

EDIT: Someone can't get my question so I decided to explain in more details.

(^(((?:abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz|012|123|234|345|456|567|678|789|(0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)'\'1{2})).)*|^['\'x20-\x7E]+$)

You can try this regex from https://regex101.com/

This is not working the way i want. 3 consecutive characters aren't allowed ok but it is not checking non-english characters. For example if you type ğğğ That will be accepted. I put | operator between them. It's wrong I know. I gotta put AND operator but I don't know How can AND operator be used in a regular expression? That's actually the main problem.

You can use the following:

^(?!.*(?:abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz|012|123|234|345|456|567|678|789|([\da-z])\1{2}))[\x20-\x7E]+$

正则表达式可视化

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM