Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have two problems, one of them is a regex

Tags:

c#

regex

.net-3.5

I am updating some code that I didn't write and part of it is a regex as follows:

\[url(?:\s*)\]www\.(.*?)\[/url(?:\s*)\]

I understand that .*? does a non-greedy match of everything in the second register.

What does ?:\s* in the first and third registers do?

Update: As requested, language is C# on .NET 3.5

like image 878
Guy Avatar asked Dec 06 '22 05:12

Guy


1 Answers

The syntax (?:) is a way of putting parentheses around a subexpression without separately extracting that part of the string.

The author wanted to match the (.*?) part in the middle, and didn't want the spaces at the beginning or the end from getting in the way. Now you can use \1 or $1 (or whatever the appropriate method is in your particular language) to refer to the domain name, instead of the first chunk of spaces at the beginning of the string

like image 79
VoteyDisciple Avatar answered Dec 17 '22 10:12

VoteyDisciple