[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Regexp] (no subject)
From: |
Jino John Thevareth |
Subject: |
Re: [Regexp] (no subject) |
Date: |
Tue, 26 Aug 2003 16:41:28 +0530 |
I think this is what he means:
Assuming that this is the list of characters he wants to search for
[a-zA-Z0-9,.'&@_-]
In the given string, he wants to search for these characters , but he
wants to ignore if he finds two given characters adjacent to each other...
For example, if he were searching for just the three characters a b
c,
he should extract these characters only when they are present
individually.....
He shouldn't extract characters like ab, ac, bc or even abc ,
because here you have valid characters adjacent to each other.
For this simple example, I would write a regular expression like this:
[^abc][abc][^abc]
This just means that I'm searching for the characters a, b or c ,
provided these characters are not surrounded by a, b, or c
But before parsing the string, you will have to append a single (junk)
character to both ends of the string...
Unfortunately, I don't have the required set up in my computer to try this
out... Could any one please add to what I said and help him out...
regs,
Jino
_____________________________________________________________
_____________________________________________________________
If I understand you correct. You can catch this with repeating
operators. See this from the manual:
-----------------------------------------------
# Repeating Operators
These symbols operate on the previous atomic expression.
? matches the preceding expression or the null string
* matches the null string or any number of repetitions of the
preceding expression
+ matches one or more repetitions of the preceding expression
{m} matches exactly m repetitions of the one-character expression
{m,n} matches between m and n repetitions of the preceding
expression, inclusive
{m,} matches m or more repetitions of the preceding expression
-----------------------------------------------
[a-zA-Z0-9,.'&@_-]{2,} would catch all occurences of at least two of
your character class.
Greetings
Thomas
MarK Neisler wrote:
> I have a problem that I am trying to solve using regular expressions.
>
> To validate form input we have a java bean that will take a regular
> expression to match for validation.
>
> Here is the regular expression I have.
>
> [a-zA-Z0-9,.'&@_-]
>
> this works however I need a regular expression that will disallow any of
> the symbols being next to each other in the string. for instance -- -,
> @@ &' ,- and so on. Any suggestions? I have been working on this for 3
> days any help greatly appreciated.