write2mtg

Hi All,

I want to have a negated character class only for few characters, the rest of the chracters should have a normal meaning.

I have given an example

[(^a)\d]$

I want the negation only to occur for "a" and not for the "\d".

Is there any way to do this.

Thanks,

Murali



Re: Regular Expressions Negated Character class

OmegaMan

By simply saying

[^a]

that will allow any character except an a. So these are valid

b
1
#

If you need to exclude other characters just do

[^a#]

which then allows one character that is not an a or a #. Otherwise just to allow items away from a and digits do this

[b-z0-9]

which will only allow on character within the range b-z and numbers 0-9.





Re: Regular Expressions Negated Character class

write2mtg

No OmegaMan, I think either my question is not properly phrased or its misinterpreted by you.

wat I need is a negated character class only for few characters.

for example

[^as] - what this does is allow any characters other then 'a' or 's' . By default negation applies to all characters in a chracter class.

But what I require is

Allow any character other then 'a' and it should be followed by 's'. This is should get in a character class.

I tried this [^a(s)] but this is not working.

so is there any way to get around this.

Thanks,

Murali





Re: Regular Expressions Negated Character class

OmegaMan

write2mtg wrote:

Allow any character other then 'a' and it should be followed by 's'. This is should get in a character class.



[^a]s

Which says one character (not a) then a required s. Works on

ds
1s
#s

but not

as







Re: Regular Expressions Negated Character class

write2mtg

Hi,

sorry for the late reply.

Yes, I accept that but it no way answers my question Omega.

I want the same output when that "s" is also included in the character class like [^as].

What I want to know is whether we can have negation only for the first character after the Carat symbol and the remaining characters exist as it iswithout negation.

I even tried this but in vain.

[(^a)s]

I hope now Im very clear and hope i can have a solution to this.

Thanks,

Murali





Re: Regular Expressions Negated Character class

Jackson McCann

The negation applies to everthing in the square brackets. [^as] will match any character except a and s and I don't know of any way to change this. I think you need to give us a bit more information on what it is you are trying to achieve,

Going back to your original example, [(^a)\d]$, what do you want this to mean From what you have said I think that you want to find a single character that isn't an a but that is a digit at the end of line - however if a character is a digit it isn't an a so \d$ should work. This doesn't seem right though so I'm guessing what you really want is to find a single digit at the end of a line when the digit is preceded by anything other than an a. [^a](\d)$ might be what you need.

Some example text (not too much) showing what you want to match and not match would help us help you here!

Good Luck






Re: Regular Expressions Negated Character class

OmegaMan

write2mtg wrote:

What I want to know is whether we can have negation only for the first character after the Carat symbol and the remaining characters exist as it iswithout negation.

I even tried this but in vain.

[(^a)s]



There is no such nesting as you found out. Try this instead

Code Snippet

[^a][s]



which says find two characters anb apply these two set rules
  1. The first character will be anything but an a character
  2. The second character must be an s.





Re: Regular Expressions Negated Character class

write2mtg

I think so . Thanks for ur effort.