1

I'm trying to find all rows that have multiple underlines in them separated by some characters, like: The boys ____ to the store to ___ up some groceries

I tried SELECT * FROM "Questions" WHERE "questionText" LIKE '%_%_%' but this seems to return everything.

2
  • Can you be more specific? Would 'x__x' qualify? How about '______ x' or 'x _'? Commented Jun 30, 2016 at 20:39
  • Hi _, this is _. would qualify More than one ____ would not qualify Just one _ would not qualify Commented Jun 30, 2016 at 20:43

1 Answer 1

2

You can use :

  SELECT * FROM questions WHERE questiontext ~ '[ $][_][$ ]';

for the case of 2 elements containing space character and underscore:

  SELECT * FROM questions where questiontext ~ '^[^_]+_([^_]+)_[^_]+$';
Sign up to request clarification or add additional context in comments.

7 Comments

What does the ~ do? and the [?
It's a regular expression - a class that ~ passes to evaluate. See regular expressions in postgresql.
This returns things like She was ____ because she had only gotten three hours of sleep.. I only want to return things that have an underline separated by non-underlined character, such as: She was ____ because she had only gotten three hours of __.
You add more classes to the regexp [^$][___][^$] - ^$ means empty string
Well.. to be clear, I want ONE and only one _. So... Jack went to the _ to pick up some _.
|

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.