1
"regexp": {
  "commonStructure": {
    "value": "[^>]*?[,<]PRP[,>][^\\<]*?\\s[^>]*?[,<]VERB[,>].*",
    "flags": "ALL"
  }
}

The pattern is correct and its working in js and python

And her is the example string

<PRP,PRON>{I} <VBD,VERB>{worked} <ADVPL,IN,ADP>{in} <NNP,PROPN>{London} <IN,ADP>{at} <ADVTMRI,RB,ADV>{first} <PUNCT>{,} <CC,CCONJ>{but} <PR,PRON>{it} <VBD,VERB>{was} <RB,ADV>{not} <JJ,ADJ>{easy} <TO,PART>{to} <VB,VERB>{make} <NN,NOUN>{money} <ADVPL,RB,ADV>{there} <PUNCT>{.}

In this pattern, I want to get all records that have first [PRON] and the next neighbor is the [VERB]

note that in this pattern with first [PRON] i can pass also the word in this case {I}

5
  • If the regex works in Python and JS, it does not mean it will work in other regex flavors. \s is not supported by the Lucene regex engine. Try "[^>]*[,<]PRP[,>][^\\<]*[ \t\r\n][^>]*[,<]VERB[,>].*". BTW, what did you match with [^\\<]? Commented Aug 16, 2018 at 11:42
  • Here is the supported regexp syntax for Lucene: elastic.co/guide/en/elasticsearch/reference/current/… Commented Aug 16, 2018 at 11:46
  • Tanks @WiktorStribiżew jan your suggestion is really helpful and its fixed my issue, But it's so strange that \s isn't working in regex Commented Aug 16, 2018 at 11:49
  • @WiktorStribiżew [^\\<] it is a typo from copy-pasting it must be [^\<] and yes I know that the correct one is [^<] Commented Aug 16, 2018 at 11:53
  • @WiktorStribiżew I Tink this sone about you youtube.com/watch?v=IB7s3YlbU9U Commented Aug 16, 2018 at 11:55

1 Answer 1

1

Lucene regex engine does not support common NFA regex shorthand character classes.

To match a whitespace, you may use your own bracket expression like [ \t\r\n], or [ \f\n\r\t\v].

To match any char but <, use [^<], do not escape < as it is not a special regex char.

So, you may use

"[^>]*[,<]PRP[,>][^<]*[ \t\r\n][^>]*[,<]VERB[,>].*"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.