Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8517755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:47:38+00:00 2026-06-11T05:47:38+00:00

I’m trying to parse a simple filter condition using regular expressions The filter should

  • 0

I’m trying to parse a simple filter condition using regular expressions

The filter should have the following syntax:

field=value
field:value
field!=value
field<>value
etc... (you get the idea)

I came up with the following (in scala)

val FilterEntry = """^(\w+)(!?)(=|:|<=|>=|<>|<|>)(.*)$""".r
val FilterEntry(v1, v2, v3, v4) = "field!<>value"
v1: String = field
v2: String = !
v3: String = <>
v4: String = value

So it’s a fine start

Now I’d like the regular expression to catch (raise an error) when no value is passed

I tried with this (I made the last group non optional)

val FilterEntry = """^(\w+)(!?)(=|:|<=|>=|<>|<|>)(.+)$""".r
val FilterEntry(v1, v2, v3, v4) = "field!<>"
v1: String = field
v2: String = !
v3: String = <
v4: String = >

So the problem is that it recognizes the operator as “<” and th value as “>” instead of correctly recognizing the operator as “<>” and the value as “” (If I test it with the firest reg exp, it correctly recognizes the operator as <> and the value as “”)

I guess I should tell the regular expression to match the operator greedily, but I thought it was like that by default…

— edit

I’ve just found this scala console online, for you the test the regular expression
http://www.simplyscala.com/

—

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:47:39+00:00Added an answer on June 11, 2026 at 5:47 am

    The are greedy, yes, but that does not mean they may not back track. You need a possessive quantifier for that.

    Try this one: ^(\w+)(!?)(=|:|<=|>=|<>|<|>){1}+(.+)$

    Note that the order of the alternations in the operators start to matter… If the < alternative appears before <= and <> then the match engine will always greedily match < first and then not even attempt to match the longer <= or <> options. If you just sort your alternatives by length from longest to shortest you should never have this problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.