-1

I'm looking for the regex expression for a string matching a string starting with a ; and ending with a :, that contain neither ; nor :

For example ";zreazer:" should match but ";raz:er:" or ";er;:" should not.

Any idea? :) Thanks in advance, I tried some with ^ and ?! symbols but it didn't work out very well.

cs95
  • 379,657
  • 97
  • 704
  • 746
Axel Carré
  • 303
  • 1
  • 5

1 Answers1

2

I believe you're looking for

;[^;:]*:

; and : are the delimiters. [^;:] will match any string in between the delimiters that does not include these delimiters.

Here's a Regex101 demo. I've added double quotes to the expression to make it obvious.


A good reference for regular expressions can be found here in the Python docs.

cs95
  • 379,657
  • 97
  • 704
  • 746
  • What exactly does non-greedy match mean? – MichalH Jul 31 '17 at 23:20
  • 1
    @Mike This link will answer your question much better than I can in the comments: https://stackoverflow.com/questions/2301285/what-do-lazy-and-greedy-mean-in-the-context-of-regular-expressions – cs95 Jul 31 '17 at 23:21
  • 1
    What is the point of making it non-greedy here? You are looking for string which starts with `;`, ends with `:` and has no `;:` between. – Pshemo Jul 31 '17 at 23:24
  • @Pshemo Point. Edited :] – cs95 Jul 31 '17 at 23:45