L
L
lexstile2021-09-09 18:35:16
Regular Expressions
lexstile, 2021-09-09 18:35:16

How to write a regular expression to capture several OKVED?

I tried to write myself: But it's not right and not up to the end. You need to capture the following types of oqueds ( 1 === \d{1} ):^[\d]{2}(?:[\.\,]{0,2}[\d]{0,2})$


  • eleven
  • 11.1 (or 11.1)
  • 11.11 (or 11.11)
  • 11.11.1 (or 11.11.1)
  • 11.11.11 (or 11.11.11)
  • 11 11.11 11.11.11
  • 11 11.11 11.11.11


Invalid:
  • 11. (or 11,)
  • 11.1. (or 11.1,)
  • 11.11. (or 11.11,)
  • 11.11.1. (or 11,11,1,)
  • 11.11.11. (or 11,11,11,)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2021-09-09
@lexstile

^\d\d(?:[ .,]\d\d?)*$
https://regex101.com/r/HNNPVh/1
If invalid:

  • 11.11.11
  • 11.11.11
  • 11.1.11
  • 11.1.1

^\d\d(?:([.,])\d(?:\d(?:\1\d\d?|)|)|)(?: \d\d(?:([.,])\d(?:\d(?:\2\d\d?|)|)|))*$

https://regex101.com/r/HNNPVh/2

V
Viktor Taran, 2021-09-09
@shambler81

d(?=r) matches d only if followed by r but r will not match expression -> test
(?<=r)d matches d only if preceded by r but r will not match match expression -> test
plus
[^d]+ all up to d

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question