Warm tip: This article is reproduced from stackoverflow.com, please click
regex

Regex: How to match string which is not containing one certain character and it combinations side by

发布于 2020-03-27 10:27:36

I am trying to match everything except * or ** or infinity number of *

I have already writed such regex:

^(?!\*).+$|^.*[^\*]$|(?<=\*).+

I need to add or statement which would remove match: '****' Or write entire new one which:

Should not match when *

Should not match when **

Should not match when ***

ect.


Should match when A9()*

Should match when *A9()

Should match when A(*

Should match when A*()*

Should match when A9*)

Should match when A9()

ect.

Live example: https://regex101.com/r/pw2z9E/1

Questioner
KamilSocha91
Viewed
82
Vitalii 2019-07-03 23:31

You can use length operator to determine minimum length of each symbol. For example:

(\w{1,}\*{1,}|\w+)

UPD

To include special characters use this modifications:

([^*\s]{1,}\*{1,}|[^*\s]+)