T
T
Toma2018-06-25 11:51:06
Regular Expressions
Toma, 2018-06-25 11:51:06

Is it possible to somehow simplify the regular expression of the form YayoYo]|.{0})$?

I wrote a regular expression, it works, but it looks
ugly ЯА-ЯёЁ]|.{0})$
The task is as follows: in the string you need to find a correspondence between IP or MCU, so that
1. If there are other Russian letters before MCU|IP, then there must be a space before MCU|IP
2. If after MKU|IP there are other Russian letters, then after MKU|IP there must be a space
3. The line can be a simple "MKU" or "IP" 4. MKU
|IP can be at the beginning or end of the line
quotes or other non-Russian characters
Examples with IP
1. true: "Sasha IP" false: "SashaIP"
2. true: "IP Sasha" false: "IPSasha"
3. true: "IP"
4. true: "Sasha Ivanov IP" false: "Sasha Ivanov IP"
5. true: "IP'Sasha'"
5. true: "@[email protected]"

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Toma, 2018-06-25
@tomatenshi

As a result of the nationwide assistance, this came out =
)

K
Kudis, 2018-06-25
@kudis

(^|\s)(МКУ|ИП)($|\s)
So:
IP Sasha - true
IPSasha - false
MKU Sasha - true
MKUSasha - false This is MKU Sasha
- false
This is MKU Sasha - true
Did I understand the task correctly?

D
DENIS Kokorev, 2018-06-25
@shmaroder

The first law of programming:
1. If something works, don't touch it.
Give examples of strings by your numbers. This will make it easier to understand the problem.
1....
2...
...
5...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question