N
N
Nulltiton2022-04-02 06:49:05
Regular Expressions
Nulltiton, 2022-04-02 06:49:05

How to set a condition in a regular expression?

There is a regular expression:

@"\b\(d{1})*?-??(\d{1})*?\s.*" + surname + @"\s.*(\d{1})\b";
, which works with strings like:
  • 4. Sub 1-2 Fam 53
  • 5-6. Sub 1-2 Fam 51

If there is a "-" sign, then you need to count two numbers, before and after "-", if not, then only one number
The expression incorrectly processes the first line and displays 37 4. Sub 1-2 Fam 53
Is it possible to bind the number of numbers to be read to the "-" sign?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question