Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract all Parameters with RegEx

Tags:

c#

.net

regex

I have the following SQL sample statement in a string variable

INSERT INTO T_Application
(
    ApplicationGroupId,
    Name,
    Component,
    SubComponent,
    Description
)
VALUES
(
    @ApplicationGroupId,
    @Name,
    @Component,
    @SubComponent,
    @Description
)

SET @Id = SCOPE_IDENTITY()

What I want is to have all Parameter names (Id, ApplicationGroupId, Name, Component, SubComponent, Description) in a List<string>. How can I write the RegEx to extract all Parameters Names? The RegEx should also work if the Parameters are in one line, spaces between , etc.

like image 757
gsharp Avatar asked Dec 28 '22 17:12

gsharp


1 Answers

Regex.Matches(sql, @"\@\w+").Cast<Match>().Select(m => m.Value).ToList ();

Resulting List:

@ApplicationGroupId
@Name
@Component
@SubComponent
@Description   
like image 166
agent-j Avatar answered Dec 30 '22 09:12

agent-j