I want to create a Regex that separates any number of words by semi-colons. For example:
word1 word2;word3 word4;word5 word6....
Here's what I've tried:
^.*(;){0,}
But this allows using more than one semi-colon side by side.
Based on your comment, you need an expression that matches a string of words separated by either a semicolon, a space, or both.
^(\\w+( ;?|; ?))+\\w+$
Explanation:
^ | Enforce beginning of string
( | Group the following:
\w+ | One or more consecutive word characters
( ;?|; ?) | A space, semicolon, or combination of the two
)+ | End group; match one or more of them
\w+ | One or more consecutive word characters
$ | Enforce end of string
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.