0

I am trying to build a regex to identify the parameterized property of VB.

Example code of a parameterized property i want to match

Public ReadOnly Property Test(v as String) As Integer
Public ReadOnly Property Test(ByVal v as String) As ReadOnlyCollection(Of Guid)

Example code of a property i want to avoid

Public ReadOnly Property Test() As Integer         
Public ReadOnly Property Test() As ReadOnlyCollection(Of Guid)

Basically if there are any parameters passed to the property i want it to match, but there are other cases with other parenthesis in the same line as the type of the property that might not have parameters. The pattern i see is

property [0 or more empty space] [next word] [0 or more empty space] ( [0 or more empty space] Target characters OR Ignore WhiteSpace [0 or more empty space] )

This is what i have so far

Property?\s+(\w+)\s*(\([^()]*\))

Sadly it does not ignore cases with the empty parenthesis.

vfle
  • 1,025
  • 3
  • 18

1 Answers1

1

Change the [^()]* to [^()]+. + makes the previous selector match 1 or more times, whilst * makes it match 0 or more times. You can read more here: Difference between * and + regex

regex101 demo

Here's what your regex should end up as:

Property?\s+(\w+)\s*(\([^()]+\))
Ethan
  • 4,165
  • 4
  • 22
  • 41