How to get 3 conditions for matching in PHP regular expression?

I am trying to write a regular expression and matches 3 conditions and will return true if all three are satisfied .

Condition 1) string starts with a "{"

Condition 2) string DOES NOT contain a space somewhere between brackets

Condition 3 string ends with a "}"

So far I have come up with ^{|[ ]|}$one that checks for a space. But I need to do this if there are no spaces between the brackets . It will also return true if the string begins with {but does not end with a character }and vice versa. I was messing around with regex101.com, but I can’t determine if there is any part of the space.

Can someone explain how to match if there is no in the line ?

+4
source share
1

,

/^{\S*}$/

regex.

  • ^ -
  • { - {
  • \S* - 0+,
  • } - }
  • $ - .

, , - , 2 :

  • 1) , , char: (, ^[^;]*$ , ; ), "" class ( , \S \S ^\S*$ , )
  • 2) , , : (, like: ^(?!.*like).*$ ^(?!.*like)).
+3

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


All Articles