0

i've being trying this without success:

select * from table where name regexp '^[:alpha:]{2}$'

pls help me?

1
  • are looking for only two match result Commented Jun 4, 2011 at 14:01

2 Answers 2

1

There probably needs to be some white space in between the two words, right? Try

select * from table where name regexp '^[[:alpha:]]+[[:space:]]*[[:alpha:]]*$'
  • [[:alpha:]]+ matches one or more letter characters
  • [[:space:]]* matches zero or more whitespace characters. (You may want to use [[:blank:]]* instead, to only match spaces and tabs, or [[ ]]* for spaces only.)
  • [[:alpha:]]* matches zero or more letter characters

So this should accept strings like

  • "foo"
  • "foo "
  • "foo "
  • "foo bar"
  • "foo bar"

and reject strings like

  • " foo"
  • " foo "
  • "foo bar baz"
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, but in order to make this work I had to use, for exemple, [[:alpha:]] instead of just [:alpha:]
0
select * from table where name regexp '^[:alpha:][:blank:]^[:alpha:]*$'

1 Comment

That can't possibly work, since each bracket expression will only match a single character, and the regex contains two mandatory ^ anchors.

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.