[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 585
  • Last Modified:

(Regex) how do I invalidate a string if it contains a certain character?

Hi, I am trying to do the following with regular expressions.
I want every string to match unless it contains the characters ( ) or "
i tried
(.*)?[^()"]
but the string "hello (world)" was still a valid match.
I also tried
(.*)?(?![()"])
which still matched "hello (world)"

some help? what am I not understanding here?
0
colonel720
Asked:
colonel720
  • 3
1 Solution
 
mahomeCommented:
That should do: [^()"]*
0
 
mahomeCommented:
With the part (.*)? you will always match anything, it means: any character, any times (inner part), 0 or 1 time (outer part)
0
 
colonel720Author Commented:
I actually tried that, and it was partially matching "hello (world)".. I am using an evaluator that returns a bool if the string matches or not. it worked when i anchored it like \A[^()"]\z
Thanks
0
 
mahomeCommented:
Yes you're right I forgot the anchors.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now