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>

  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; }   

and tested it on the following input:

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.

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 matchAll correctly?

. Captures are similar to .front , which means match first. If you are interested in all the matches, then drop .captures

Then, 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 ;

* or before deposit - they are the same, because the whole thing is bracketed


Perhaps it can help clarify some things Is:

  • MatchL (...) returns in several matches:
    • The first match is a series of complete matches and submissions:
      • Full match: "% template"
      • First deposit: "% templates"
      • Second match:
        • complete Match: "% template_arguments"
        • For the third match:
          • Full match: "% template1"
          • The first set : "% Template 1 "
          • ...

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -