0

I have regex something like below:

f04((?!z).)*

Requirements :

1.)f04 matches the characters f04 literally (case sensitive)

2.) Assert that the Regex below does not match, z matches the character z literally (case sensitive)

3.) . matches any character

What can be the other possible way to write this particular regexp with the same requirements as above?

zubug55
  • 729
  • 7
  • 27

1 Answers1

0

Here is one alternative:

f04(.*?)(?=z|$)

Demo

This pattern will match f04 followed by anything until either hitting the first letter z, or until hitting the end of the entire string, should a z never occur.

Your current approach uses a tempered dot, but both patterns should behave similarly.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Can you plz help me on this question: https://stackoverflow.com/questions/51783196/regexp-character-doesnt-work-in-es-dsl-query-even-on-type-set-as-keyword-i – zubug55 Aug 12 '18 at 06:33
  • i just tried to do something like this ^(f04ba)[^z]+?$ instead of this f04((?!z).)* to avoid answers with z; and it did work. Does this thing gives you any hint that why ! in the regexp query doesnt give any results in my elastic search case? – zubug55 Aug 12 '18 at 08:31
  • @zubug55 Yes, it implies that Elastic Search does not support lookarounds. – Tim Biegeleisen Aug 12 '18 at 10:20
  • you know what i think i found the solution -> https://stackoverflow.com/questions/38645755/negative-lookahead-regex-on-elasticsearch -> so i have to do something like this -> .*f04.*&~(.*z.*) – zubug55 Aug 12 '18 at 10:21