ich versuche, eine Super grundlegende Template-Sprache zu entwickeln, und ich habe ein Problem mit RegEx, ich versuche, diese zu konvertieren:Regex Kette Ersatz Ausgabe
# Tilte
## Subtitle
### Subsubtitle
Lorem ipsum b(dolor) sit i(amet), consectetur u(adipisicing) elit
dazu:
<h1>Title</h1>
<h2>Subtilte</h2>
<h3>Subsubtitle</h3>
Lorem ipsum <strong>dolor</strong> sit <i>amet</i>, consectetur <u>adipisicing</u> elit
aber ich bekomme diese:
<h1></h1>
<h2>TEma 4</h2>
<h3>Subtitle</h3>
Lorem ipsum <strong>Subsubtitle</strong> sit i(amet), consectetur u(adipisicing) elit
Hier ist mein Code:
input = ARGV[0]
regExes = {
h1: [/^# (.*)$/, "<h1>", "</h1>"],
h2: [/^## (.*)$/, "<h2>", "</h2>"],
h3: [/^### (.*)$/, "<h3>", "</h3>"],
b: [/b\((.*)\)/, "<strong>", "</strong>"],
}
strFile = File.read input
puts "\t", strFile
for index, regEx in regExes
actualNode = regExes[index]
print actualNode, "\n"
strFile.gsub! actualNode[0], "#{actualNode[1]}#{$1}#{actualNode[2]}"
end
puts strFile
Was soll ich tun?
Verwenden faul Matching: '/ b \ (.? (*) \) /' –
Ok, eine Sache gelöst ist, aber ich habe immer noch die Probleme mit ** der h-Gruppe Tags * * –
** das Problem in den Werten liegt, die Sätze sind ** –