Rub, regex, sentences

Posted by Perello on Stack Overflow See other posts from Stack Overflow or by Perello
Published on 2012-09-20T15:34:21Z Indexed on 2012/09/20 15:37 UTC
Read the original article Hit count: 397

Filed under:
|

I'm currently building a code generator, which aim to generate boiler plate for me once i wrote the templates and/or translations, whatever the language i have to work with, and it has an educationnal part :p.

So i have a problem with a regex in ruby. The regex aim to select whatever is between {{{ and }}}, so i can generae functions according to my needs.

My regex is currently :

/\{\{\{(([a-zA-Z]|\s)+)\}\}\}/m

My test data set {{{Demande aaa}}} => {{{tagadatsouintsouin tutu}}}

The results are : [["Demande aaa", "a"], ["tagadatsouintsouin tutu", "u"]]

So the regex pick each time the last character twice.

But, that's not exactly what i want, my need is more about this :

/\{\{\{((\w|\W)+)\}\}\}/m

But this as a flaw too, the results : [["Demande aaa}}} => {{{tagadatsouintsouin tutu", "u"]]

Whereas, i wish to get [["Demande aaa"],["tagadatsouintsouin tutu"]]

Any ideas to correct theses regex ? I could use 2 sets of delimiters, but it won't learn me anything.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about regex