0
$$(issues) filter({ createdAt: { $gte: moment(new Date('2018')).endOf('year').toDate() } }) pickBy(createdAt) as(issues)

parenthesis inside parenthesis should not match

so the value will only

issue
{ createdAt: { $gte: moment(new Date('2018')).endOf('year').toDate() } }
createdAt
issues

this match all parenthesis which is wrong

\((.+?)\)

enter image description here

crapthings
  • 2,435
  • 2
  • 18
  • 31
  • In JS you cannot do this by regex. You will need to use a parser? – anubhava Oct 18 '19 at 06:34
  • your expression will be always with the same structure? still pickBy (createdAt) as (issues) at the end? always $$ (issues) at first? still filter the keyword? It can sometimes contain an additional prefix or suffix? – Eric Oct 18 '19 at 06:43
  • For this sample data `/\((.*?)\)(?=\s|$)/g` may work with assumption that there is a whitespace or line end after closing `)` See this demo: https://regex101.com/r/m1e5Bt/1 – anubhava Oct 18 '19 at 06:44
  • @Eric $$(groups) pickBy(parentGroupId, shortName, name) as(groups) $$(users) pickBy(profile.name) as(users) $$(issues) pickBy(title, groupId, createdById, createdAt) as(issues) ref(groups) keyBy(_id) as(groups) ref(users) keyBy(_id) as(users) ref(issues) map(groupId = groups.shortname || groups.name, createdById = users.profile.name, createdAt = @YYYY) as(issues) pivot rows(createdAt, createdById, groupId) dict(groups, users) output(issues) – crapthings Oct 18 '19 at 06:45
  • i've found that there's recursive pattern but doesn't work with js https://stackoverflow.com/questions/14952113/how-can-i-match-nested-brackets-using-regex?answertab=votes#tab-top – crapthings Oct 18 '19 at 06:51
  • 1
    You may find a couple of JS solutions, see [here](https://stackoverflow.com/a/35271017/3832970) and [here](https://stackoverflow.com/a/25093078/3832970). – Wiktor Stribiżew Oct 18 '19 at 06:58
  • @WiktorStribiżew wow kool, i m trying now – crapthings Oct 18 '19 at 07:08
  • 1) Do you use lodash javascript api? 2) what is the ultimate goal? 3) can the problem be solved with lodash? If not, use a Lex analyzer to create an abstract tree, but you must provide a grammar. 3b) Once the tree is built, go through it and recreate what you need. – Eric Oct 18 '19 at 07:12
  • yes i mix lodash and mongo db query work together, i don't want to translate all grammar to mongo query pipeline because i still have to operate normal jsobject – crapthings Oct 18 '19 at 07:26
  • is there any js Lex analyzer easy to use? i have no experience to lex analyzer – crapthings Oct 18 '19 at 07:33

0 Answers0