Capturing and storing all matches for regex using D -
I'm trying to capture every instance of the text with numbers, numbers and underscores after the% symbol, unless I have written the following regex to do this:
I want to store everything to capture it in an associative array like this, and so I wrote the following function to do it: / P> and tested it on the following input: Which I wrote as a escape string I think it will give me 9 matches (but confirmed), but for some reason, I only get 1! Am I using Then, * or before deposit - they are the same, because the whole thing is bracketed Perhaps it can help clarify some things Is: ((?
string [string] Make_symbol_table (string input) {string [string] symbol_table; Automatic M = Match All (Input, Regedx ("(?? & Lt;! (?: \\ |%))% [a-zA-Z0-9 _] +)", "G")) . Capture (); (Auto i = 1; i & lt; m.length; i ++) for {symbol_table [m [i]] = null; } Return symbol_table; }
This is a simple% template, with some well-located% template_arguments. It uses a range of characters, mostly to ensure that% template1 works correctly. \ N \ nYou can also start a% 1 template with a number! We may also have some silly matters:% _% 1,% a, and so on. Should never be captured in %% method, nor should you run from \\% or \\% \\%% CAPS or% CaPs are OK too.
matchAll correctly?
. Captures are similar to
.front , which means match first. If you are interested in all the matches, then drop
.captures
m is a
RegexMatch , in which
.length . Just more than
foreach :
foreach (match; m) .
match is a
occupied , complete match and all submatches have a limit. If you are interested in full match * then use
match.front or
match [0] to get the string:
symbol_table [match.front] = null ;
MatchL (...) returns in several matches:
Comments
Post a Comment