Results 1 to 2 of 2
  1. #1
    bill.jones is offline Member
    Join Date
    Jul 2016
    Posts
    1
    Rep Power
    0

    Question Phrase ending with value regular expression

    Hello,

    I am using Lucene in the context of Elasticsearch. I am trying to figure out how to write a regular expression query that will match the end of a phrase (not a term).

    In my search index, I have a field that has flavors of ice cream. This data is just made up to demonstrate my problem. So, some examples are:

    Chocolate
    Rocky Road
    Cookies and Cream
    Peaches and Cream
    Butterscotch
    Cream and Berries
    Vanilla

    Currently, I have this query:
    Java Code:
    flavor:/.*ream/
    That query returns the following three results:

    Cookies and Cream
    Peaches and Cream
    Cream and Berries

    But, I really just want to have the top two results returned:

    Cookies and Cream
    Peaches and Cream

    I do not want the last result. I know it has to do with the fact that the regular expression is matching on terms instead of the field value. My question is, is there a way to make a regular expression that will match the ending of a field value (instead of a term)? If so, how?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Phrase ending with value regular expression

    Try sticking a $ sign at the end. That should be end of line match. And ^ should be beginning of line.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Regular Expression
    By allaudin in forum New To Java
    Replies: 8
    Last Post: 10-02-2013, 09:26 AM
  2. Regular expression
    By garnaout in forum New To Java
    Replies: 4
    Last Post: 05-15-2012, 06:22 PM
  3. Help with regular expression
    By mr.ab18 in forum New To Java
    Replies: 2
    Last Post: 08-06-2010, 10:01 PM
  4. regular expression
    By prof.deedee in forum JDBC
    Replies: 3
    Last Post: 02-19-2010, 11:15 AM
  5. regular expression
    By QkrspCmptPop in forum Advanced Java
    Replies: 8
    Last Post: 01-20-2010, 03:55 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •