Some Regex help

I currently use this regex to match a set of braces with something inside them (i.e. [lol]):


The problem is that I want it to only match this if it is at the beginning of a string, and not if it is in the middle of one. I’ve tried various things, but none worked:




Try this:


Thanks, that worked perfectly :slight_smile:

Mind telling me what you did there, I want to learn something from this too, you know :wink:

read this page and a few on from there.

Okay, thanks. % is the same as \ (backslash) and - is the same as *. Thanks for your help :slight_smile:

This is not true.

If I have this string:

str = "hope:slope:rope"

And these two patterns:

a = "(.-):(.+)"
b = "(.*):(.+)"

And run this code:

print( str:match( a ) )
print( str:match( b ) )

This is the output:

hope        slope:rope
hope:slope        rope

  • grabs the shortest possible match while * grabs the longest possible, as you can see above.