Ruby Regex: Match Until First Occurance of Character -
i have file lines vary in format, basic idea this:
- block of text #tag @due(2014-04-20) @done(2014-04-22) for example:
- email john doe #email @due(2014-04-20) @done(2014-04-22) the issue #tag , @due date not appear in every entry, like:
- email john doe @done(2014-04-22) i'm trying write ruby regex finds item between "- " , first occurrence of either hashtag or @done/@due tag.
i have been trying use groups , ahead, can't seem right when there multiple instances of looking ahead for. using second example string, regex:
/-\s(.*)(?=[#|@])/ yields result (.*):
email john doe #email @due(2014-04-22) is there way can right? thanks!
you're missing ? quantifier make non greedy match. , remove | inside of character class because it's trying match single character in list (#|@) literally.
/-\s(.*?)(?=[#@])/ see demo
you don't need positive lookahead here either, match until characters , print result capturing group.
/-\s(.*?)[#@]/ you use negation in case.
/-\s([^#@]*)/
Comments
Post a Comment