Как насчет использования mem::zeroed
? Документы ( https://doc.rust-lang.org/std/mem/fn.zeroed.html ) даже говорят:
Это полезно для FFI функции иногда, но обычно их следует избегать.
blockquote>
Вы должны искать строку ://
, (Положительный взгляд за спиной), если она входит в строку, значит, это домен, и вам нужно захватить все после этого. Имеет ли он @
или нет.
Случай 1
Захват всей строки после ://
Регулярное выражение:
(?<=\:\/\/).*
[1156 ]
Объяснение:
Positive Lookbehind (?<=\:\/\/)
Assert that the Regex below matches
\: matches the character : literally (case sensitive)
\/ matches the character / literally (case sensitive)
[119 ]
.* matches any character (except for line terminators)
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Пример https://regex101.com/r/jsqqw8/1/ [ 1129]
Случай 2
Захват только домена после ://
Regex:
(?<=:\/\/)[^\n|\/|:]+
Объяснение:
Positive Lookbehind (?<=:\/\/)
Assert that the Regex below matches
[1142] : matches the character : literally (case sensitive)
\/ matches the character / literally (case sensitive)
\/ matches the character / literally (case sensitive)
Match a single character not present in the list below [^\n|\/|:]+
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
\n matches a line-feed (newline) character (ASCII 10)
[1121]
| matches the character | literally (case sensitive)
] \/ matches the character / literally (case sensitive)
|: matches a single character in the list |: (case sensitive)
Случай 3:
Захват домена после ://
, если нет @
в тексте, и если @
присутствует в тексте, запишите текст после этого.
Регулярное выражение:
(?!:\/\/)(?:[A-z]+\.)*[A-z][A-z]+\.[A-z]{2,}
Объяснение:
Negative Lookahead (?!:\/\/)
Assert that the Regex below does not match
: matches the character : literally (case sensitive)
\/ matches the character / literally (case sensitive)
\/ matches the character / literally (case sensitive)
Non-capturing group (?:[A-z]+\.)*
* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below [A-z]+
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
A-z a single character in the range between A (index 65) and z (index 122) (case sensitive)
\. matches the character . literally (case sensitive)
Match a single character present in the list below [A-z]
A-z a single character in the range between A (index 65) and z (index 122) (case sensitive)
Match a single character present in the list below [A-z]+
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
A-z a single character in the range between A (index 65) and z (index 122) (case sensitive)
\. matches the character . literally (case sensitive)
Match a single character present in the list below [A-z]{2,}
{2,} Quantifier — Matches between 2 and unlimited times, as many times as possible, giving back as needed (greedy)
A-z a single character in the range between A (index 65) and z (index 122) (case sensitive)
Пример :
https://regex101.com/r/jsqqw8/4