Reputation: 11244
s = "some {text|in|braces} found"
To get the contents between braces
s.scan(/(?<={).*(?=})/) #=> ["text|in|braces"]
Now to get the contents that are not in braces, I tried
s.scan(/(?<!{).*(?!})/) #=> ["some {text|in|braces} found", ""]
Clearly I am missing something very important.
Upvotes: 3
Views: 121
Reputation: 119
Don't forget to escape special chars with \ ")(?{}".
You can solve this with 2 operations first of all you can islotale your parameter with this regex:
s = s.gsub(/.*(\{.*\}) # => "text|in|braces"
s.scan(/\w+/) # => ["text", "in", "braces"]
or
s.gsub(/.*(\{.*\}).scan(/\w+/) # => ["text", "in", "braces"]
Upvotes: 0
Reputation: 30775
Your second regular expression is looking for
which of course matches the whole string, since "some {text|in|braces} found" is neither preceded by a "{" nor followed by a "}".
Upvotes: 2