x Did you like it? Well, then please consider making a donation :)

Regular expression to match C #include file

^\s*\#include\s+["<]([^">]+)*[">] You then want to look at the first capture group when you get a match. You don't say what language you're using, the factor you mention regcomp() leads me to believe that you're using POSIX regex library in C. If that's right, then you want to use the regexec function and use the nmatch and pmatch parameters to get the first capture group.

Tags: #c, #file, #include, #language, #parsing, #programming, #source code, #text. Views: 4086. stackoverflow, 7/12/2015
Link 1: http://www.systemtextregularexpressions.com/m15/regular-expression-to-match-c-include-file
Link 2: http://www.systemtextregularexpressions.com/m15 (short)

Length: 0b, Line: 1, Cursor: 0

RegexOptions

IsMatch=true


#ValueIndexLengthGroupsCaptures
0#include <stdio.h>018Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
1#include "monkey/chicken.h"1927Skip Navigation Links.
Expand Groups [2]Groups [2]
Skip Navigation Links.
Expand Captures [1]Captures [1]
Count: 2, Time: 00:00:00

Share (without adding to database):

Source code

0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
//.NET Regex.Match Online Tester: www.systemtextregularexpressions.com

//Namespace
using System.Text.RegularExpressions;

//Regex Pattern
string pattern = @"^\s*\#include\s+["<]([^">]+)*[">]$";

//Regex example #1
Regex r = new Regex(@"^\s*\#include\s+["<]([^">]+)*[">]$", RegexOptions.Multiline);
Match m1 = r.Match("input text");
MatchCollection mc1 = r.Matches("input text");

//Regex example #2
Match m2 = Regex.Match("input text", @"^\s*\#include\s+["<]([^">]+)*[">]$", RegexOptions.Multiline);
MatchCollection mc2 = Regex.Matches("input text", @"^\s*\#include\s+["<]([^">]+)*[">]$", RegexOptions.Multiline);
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
'.NET Regex.Match Online Tester: www.systemtextregularexpressions.com

'Namespace
Imports System.Text.RegularExpressions

'Regex Pattern
Dim pattern As String = "^\s*\#include\s+["<]([^">]+)*[">]$"

'Regex example #1
Dim r As Regex = New Regex("^\s*\#include\s+["<]([^">]+)*[">]$", RegexOptions.Multiline)
Dim m1 As Match = r.Match("input text")
Dim mc As MatchCollection = r.Matches("input text")

'Regex example #2
Dim m2 As Match = Regex.Match("input text", "^\s*\#include\s+["<]([^">]+)*[">]$", RegexOptions.Multiline)
Dim mc2 As MatchCollection = Regex.Matches("input text", "^\s*\#include\s+["<]([^">]+)*[">]$", RegexOptions.Multiline)

Home     Match     Replace     Split     Help     Library     Contacts     netregex rss

Made by Koshevoy Dmitry [8Bytes],

© 2014-2024 Ukraine, Nikolaev.