-20

How to build a regular expression to check search syntax?

It says that it needs to be more focused. I don't know how to make it more focus. I asked about how to build regex for a specific case in which I gave the specs.

Also - how is it possible that it was closed so fast. I opened this a few minutes ago.

It seems like this is a mistake.

22
  • 13
    Within the regex tag, "Create a regex for me that does X" is a relatively common asked question that rarely ever proves to be useful to future visitors. It is a tag with a lot of followers/activity, and as such posts often get closed quickly
    – Kevin B
    Jan 19, 2022 at 16:45
  • 10
    The "Needs" of your question outline many different features of regular expressions that each on their own can be separate questions (and are)
    – Kevin B
    Jan 19, 2022 at 16:46
  • @Larnu - so if I remove that you think it would be ok?
    – Yehosef
    Jan 19, 2022 at 16:46
  • 1
    I wouldn't say that, no, but of the 2 distinct questions you ask, the latter is very broad. The other question you ask, "Is this something that is possible/practical with regex?" boils down to the answer "Yes" or "No"; which is unlikely the answer you want.
    – Thom A
    Jan 19, 2022 at 16:47
  • @KevinB - I'm asking for the regular expression that would solve that problem. If there is someone else that asks the question with something basically the same, then I could understand it being a duplicate - but not for "not being focused".
    – Yehosef
    Jan 19, 2022 at 16:48
  • 5
    What are the chances of somebody else having the same search grammar as yours? Jan 19, 2022 at 16:49
  • 3
    you're right, each of the individual bits of your problem could be useful to others. but you're asking for a combination of several different problems/solutions
    – Kevin B
    Jan 19, 2022 at 16:51
  • 7
    Yes. People may learn from a Question on reddit that asks how to build a website and a link response that links to a book/tutorial that goes through the entire process... but that wouldn't be on topic here because it is a question that needs more focus. What you're asking for here isn't a one and done simple question with a simple answer, it has many different pieces and edge cases that would need to be considered, many different problems that would need solutions.
    – Kevin B
    Jan 19, 2022 at 17:10
  • 2
    "The fact that you don't know how to answer the problem" that's a false assumption. The problem is that the solution is just too convoluted. Heck, I'd even suggest using plain JS instead of a single regex that will be impossible to maintain.
    – Cerbrus
    Jan 19, 2022 at 17:26
  • 3
    I would prefer that the guidance/advice would be taken into account to produce a more manageable/answerable question that would fit within the guidelines that help guide this site forward.
    – Kevin B
    Jan 19, 2022 at 17:34
  • 7
    "I opened this a few minutes ago." - A moderator saw your question, read the question, and voted to close your question. I agree with the conclusion of that moderator. If you have attempted to solve this problem yourself, certainly isn't expressed by the question body, since I only see requirements for whomever you want to write the regex for you. Jan 19, 2022 at 17:36
  • 3
    Perhaps you should refer this question: Building a parser (Part I). What you want is too broad for Stack Overflow though. You basically expect an entire parser... Jan 19, 2022 at 17:36
  • 2
    Does this answer your question? Breaking down "too broad"/"needs more focus" and trying to understand it Jan 19, 2022 at 17:39
  • 12
    It looks to be a "please do my work for me" type question, but without the "please". Jan 19, 2022 at 18:06
  • 4

1 Answer 1

18

You're asking for a whole regex, not for help with a part of a regex.

Think of it like this - you want us to help you construct the entirety of a regex that is capable of validating that someone enters "and", "or" and "not" in a specific form, complete with grouping and higher level ordering (the parentheses have value here).

You don't have any previous regex that you could submit to us that accomplishes some part of this that you're stuck with.

That sounds to me like a day or two of actual work, with Google, desk-to-head therapy sessions, and copious amounts of testing stress with those annoying edge cases of looking for "and" and not "not" or "or".

You're asking too much of us here. We can't build whole regexes for you. We could probably help you build a regex, but you'd need to provide something for us to work off of.

16
  • Are you kidding me? If I have no idea how to solve the regex so I can't ask the question because I don't have a starting point?
    – Yehosef
    Jan 19, 2022 at 16:51
  • 6
    Just to clarify - "whole regex" might be OK if the question is "how do I match digits" or similarly simple. This requires describing a whole program as a regular expression that validates the many grammatical rules for another program. Many of the features of such an application can merit a question by itself. Jan 19, 2022 at 16:52
  • 6
    @Yehosef: So what you're saying is that you have this fancy tool (regex) that you don't know how to wield that you want to use to solve a problem. Let that sink in.
    – Makoto
    Jan 19, 2022 at 16:53
  • @Makoto - ok - it sunk in. Do you want me to list the thousands of questions that do just that.
    – Yehosef
    Jan 19, 2022 at 16:54
  • And for the record, I do know how to use regex but I'm not sure how to approach this problem. I'm sorry if my ignorance is an insult to the people of StackOverflow.
    – Yehosef
    Jan 19, 2022 at 16:58
  • 5
    @Yehosef: No need. I'm talking to you about yours, and thankfully you're around to hear it. :)
    – Makoto
    Jan 19, 2022 at 16:58
  • 1
    I mean - you're basically saying that you know how to ride a bike, so you're going to pedal from San Fransisco to Juneau. There's a sizeable knowledge gap and other constraints that you have to consider before saying that you can do that. I'm not trying to insult your intelligence or ignorance here @Yehosef. I'm just trying to get you to see how daunting your ask actually is.
    – Makoto
    Jan 19, 2022 at 16:59
  • It's daunting because you don't know the answer. That's why I ask. I'm sure there is someone out there that does. I know people solve much more complicated problems with regex.
    – Yehosef
    Jan 19, 2022 at 17:01
  • 2
    I mean, i could probably solve it poking around in a regex tool for a few minutes, but that doesn't change what the question is.
    – Kevin B
    Jan 19, 2022 at 17:02
  • What the question is - a request for help solving a programming question. I can't believe what SO has turned into.
    – Yehosef
    Jan 19, 2022 at 17:10
  • 9
    @Yehosef, no, you're asking how to fly a plane when you know how to turn the ignition key. You're asking for a complex regex solution with some very specific rules, that is unlikely to be useful for future visitors. That is simply not on-topic. Now, your "what SO has turned into" and "an insult to the people of StackOverflow" are out of place here. All commenters here are trying to help you understand how SO works, so please work with us here instead of just telling all of us we're wrong.
    – Cerbrus
    Jan 19, 2022 at 17:22
  • "You're asking for a complex regex solution with some very specific rules" this is not true - what I'm asking is specific but also general - terms, groups, recursive, etc. This is completely valid.
    – Yehosef
    Jan 19, 2022 at 17:26
  • 9
    @Yehosef: Because we're also the same group of people who could consider reopening your question, perhaps listening to our advice and our perspective is more in your best interests instead of insisting against it or railing against it otherwise. You're not doing yourself any favors by defending what is a textbook "too broad" question.
    – Makoto
    Jan 19, 2022 at 17:29
  • 11
    "help solving a programming question." - Your not asking for help, you are asking for us to do it for you, there is a huge difference. There are tools that will help build a RegEx and even generate the code in whatever programming language you need it in. Jan 19, 2022 at 17:39
  • Re "...construct the entirety of a regex": Yet, the SE site Unix & Linux is a script-writing service. Just state the requirements (and perhaps some sample input data), and multiple scripts, often with regexes, will be provided in multiple scripting languages, e.g. Perl, Bash, AWK, sed, and Python. Jan 20, 2022 at 13:49

Not the answer you're looking for? Browse other questions tagged .