Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
Thread: Simple Regex Question
08-11-2008, 03:08 PM #1
- Join Date
- Sep 2007
- AZ, USA
- Thanked 46 Times in 46 Posts
Simple Regex Question
I am in the midst of learning regex and have run into a simple (I hope) question that I cannot seem to find on the net. I have the regex:
Last edited by binaryWeapon; 08-12-2008 at 03:45 AM.
08-11-2008, 04:15 PM #2
use regex or
You never have to change anything you got up in the middle of the night to write. -- Saul Bellow
08-11-2008, 04:55 PM #3
- Join Date
- Dec 2007
- Thanked 890 Times in 879 Posts
First of all is a little difference between regex for different preg function so you must first decide which one you want to use.
Second, build test cases, . That means take a string, relevant for your problem and work on it.
from what you said:It checks for a word, a comparing sign (=, >, <, etc), and another word. I want to add the sign != to the comparing signs, but obviously putting two characters interprets them as 2 different ones. How can I do this? Also, is this the most efficient way to accomplish what I'm trying to do? This is my first experience actually using regular expressions in code so I don't want to get anything wrong . I need it to check the whole string, not just part of it (ie if there was a character, a comparing sign, and another character in the middle of the string, but other characters outside, like "*$*^$a>b*)&#$&^", it shouldn't work anymore).
I need it to check the whole string, not just part of it
that means your regex start with ^ and end with $, keep in mind $
It checks for a word,
usualy this is for shor \w+, word char one or more
a comparing sign (=, >, <, etc)
usualy people use to put spaces between, but could be without, \s*, spaces zero or more
another problem are relation like <= or >=, how you deal with this? ignore or not?
and another word
same words, but with spaces before and don't forget $
I don't know if this work for you, but this is the idea,Code:^\w+\s*(=|==|<=|<|>=|>|!=)\s*\w+$
PS: if you can solve a problem without regex do it,
Users who have thanked oesxyl for this post: