B
B
Barrakuda742018-03-18 19:10:30
.NET
Barrakuda74, 2018-03-18 19:10:30

How to take the password from the text "Password complex R36yhhe3" with a regular expression?

But taking into account that the phrase can be like this:
"Password R36yhhe3"
I wanted to use this regular expression:
(?<=Пароль\ сложный|Пароль\ ).*
Assuming that the order will be observed, they say, if it does not find what comes after "Password complex", then let it look for what comes simply after "Password". But it did not work, the order is not respected, apparently it stops at the first shortest match. It always outputs "complex R36yhhe3" as a result. And I don't need the word "complex".
How to keep order in conditional OR ("|") in regular expressions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MIsternik, 2018-03-18
@MIsternik

var pattern = @"Пароль\sсложный\s([\w\d]+)";
var matches = Regex.Matches(input, pattern);
var result = match.Groups[1].Value;

just need to check, etc.
Wrote without ide, errors are possible

O
OKyJIucT, 2018-03-18
@OKyJIucT

The first part is one or more words separated by a
space
The second part is the word after the last space
(.*)+?\s(.*)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question