c# - regex extract delimited text in a pattern -
c# - regex extract delimited text in a pattern -
i attempting parse flavour of markdown has keywords in quotes or angular brackets.
words between " static keywords, , ones between < , > dynamic.
sample:
* "hello" "world" * <something> <somebody> * can plain statement the logic goes this:
find lines defined starting* check if line has keyword extract keywords if any. i have simple regex (\w+(\*.+)) helps me extract line, not sure how extend extract values between quotes or angular brackets.
update 1
so, after hint @evanknowles' link, came regex seems work, i'll happy improvements on this.
[ ]*\*([\w ]*(["\<][\w ]+["\>])*)* update 2 few people have suggested doing in steps i.e. valid lines in first pass, , keywords in each line. i'd maintain lastly option, context consumer of code needs know keywords , it's position in entire string. maintaining offset overhead inviting on splitting parent string.
below look extract keywords. seek it!
/// <summary> /// description of regular expression: /// /// origin of line or string /// [1]: numbered capture group. [.*?\"(?<keyword>.*?)\"], 1 or more repetitions /// .*?\"(?<keyword>.*?)\" /// character, number of repetitions, few possible /// literal " /// [keyword]: named capture group. [.*?] /// character, number of repetitions, few possible /// literal " /// /// /// </summary> public static regex regex = new regex( "^(.*?\\\"(?<keyword>.*?)\\\")+", regexoptions.ignorecase | regexoptions.multiline ); // capture matches in inputtext matchcollection ms = regex.matches(inputtext); use expresso tool larn , create regular expression, help create c# or vb.net code
c# regex
Comments
Post a Comment