RegEx, colon separated list

I am trying to match a colon separated list of letters. To simplify the task, I'm going to leave the email expression out of the mix and match it with any number of characters without spaces between them.

The following will fit ...

somevalues  ;somevalues;       somevalues;

or

somevalues; somevalues             ;somevalues

Ending; not required.

The following will not match.

somevalues ;   some values    somevalues;

or

some values; somevalues some values

I got it so far, but it will not work. Since I allow spaces between the colons, the expression does not know whether this word is in the word or between the colon.

([a-zA-Z]*\s*\;?\s*)*

The following is selected (which should not be e)

somevalue ; somevalues  some values;

How to make an expression that allows spaces only if there is; left or right of it?

+3
source share
4 answers

PCRE Expression .

\w+\s*(?:(?:;(?:\s*\w+\s*)?)+)?

, \w+ (?:<your email validation regex>)

Probabbly , , http://regexr.com?2rnce

EDIT: ? ; \;

+1

, ?

+6

Is the problem due to the problem? at \;?

[a-zA-Z]*(\s*;\s*[a-zA-Z]*)*

must work.

0
source

Try

([a-zA-Z]+\s*;\s*)*([a-zA-Z]+\s*\)?

Please note that I changed * to + to an email template, as I assume you don't need lines like ;.

0
source

Source: https://habr.com/ru/post/1753065/


All Articles