Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
122
rated 0 times [  124] [ 2]  / answers: 1 / hits: 44192  / 15 Years ago, tue, july 14, 2009, 12:00:00

Try as I might, I can't get a RegEx to exclude space or single quotes.




  • The string abc is allowed

  • Not allowed: a'bc, ', 'abc, ''', abc'' etc

  • Spaces could replace the ' too in the above example

  • Trailing and leading spaces are assumed to be removed already

  • Empty strings are checked elsewhere

  • Target language is javascript



I'd use PATINDEX if I was in SQL.



Or NOT a positive match on either space or single quote, if I could negate...



I've tried (for single quote only)




  • w*[^']w*

  • ^w*[^']w*$

  • others I forget now



Please put me out of my misery so I can sleep tonight.



Edit:




  • Target string will not be surrounded by Quotes. I thought thy might add clarity

  • If Target language is javascript is wrong, then it's c#. I'd have to check where we do the validation exactly: client javascript or server c#


More From » regex

 Answers
84

^[^' ]*$
?


[#99129] Thursday, July 9, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
micheleb

Total Points: 275
Total Questions: 103
Total Answers: 103

Location: Macau
Member since Sat, Jul 11, 2020
4 Years ago
micheleb questions
;