| Author |
regexp: how to make negation of a variable which saves a group number
|
alex gorn
Greenhorn
Joined: Nov 15, 2012
Posts: 5
|
|
i need to know does a symbol repeat not in a word, so i tried this:
but it has another meaning:
"Match the character with octal index 1 in the character set (1 decimal or 01 hexadecimal) «[^\1]»"
is it possible in regexp to make that?
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9946
|
|
what exactly do you mean by "a symbol repeat NOT in a word"? Are you asking for a symbol to be in a word exactly once? Not at all? Zero OR one time?
It is not clear (at least to me) what you really want.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
alex gorn
Greenhorn
Joined: Nov 15, 2012
Posts: 5
|
|
sorry, i made a mistake in first post regexp with quantifier + after [a-z], corrected.
finally i need to know amount of non-repeating symbols in the word (in abcbcacab they are "a, b, c" ). I thought to make this with regexp that find sequence of non repeating letters and i've seen that construction [^\1] doesn't work as i suggested.
May be that was not a right way to solve my task and i will find a better solution, but it's just interesting how to realize that negation of group number '\1'
thanks.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9946
|
|
alex gorn wrote:i need to know amount of non-repeating symbols in the word (in abcbcacab they are "a, b, c" ).
I still don't get it. It looks to me like each of 'a', 'b', and 'c' DO repeat. I see each of those in that string three times.
|
 |
alex gorn
Greenhorn
Joined: Nov 15, 2012
Posts: 5
|
|
language barrier)) english is not my native, sorry
i meant how many different letters are contained in the word..
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9946
|
|
No worries about the language barrier. I've worked with people who's native language is English who can't explain what they want to do.
Also, forgive me, but I don't know your programming level.
So...my first questions is...WHY do you want to do this with a regex?
Generally, you describe what you want to do first. Once you know what that is, you look for the right tool. Saying "How do I do XYZ with regexes" is similar to saying "How do I drill a hole with a hammer?" You shouldn't pick the tools first, and try to figure out how to get them to solve your task.
So...if you want to find a list of all the distinct characters, I would say that regexes are NOT the right way to go.
I will also admit that I am not a regex expert. It may indeed be possible, but it doesn't seem like the kind of thing they should do.
|
 |
alex gorn
Greenhorn
Joined: Nov 15, 2012
Posts: 5
|
|
thanks a lot for help, i expected that regexes in my case were not the right choise, but i'd like to find solution outside of programming methods - just in the context of using regular expressions.
so without attaching to the whole task, i'd like to understand why [^\1] doesn't work and how to make that construction usable.
I wrote my question in this thread because i learn java and use in training java.util.regex
|
 |
Winston Gutkowski
Bartender
Joined: Mar 17, 2011
Posts: 4747
|
|
alex gorn wrote:so without attaching to the whole task, i'd like to understand why [^\1] doesn't work
Don't know, but if you can't I suspect it has something to do with the level at which you're doing things. '\1' is a bit like a closure, which you're then trying to modify and re-apply to the same pattern. I've certainly never tried anything like it; and I've been using regexes for 20 years.
I wouldn't stake my life that it can't be done though.
and how to make that construction usable.
Simple. Find your first pattern, and then create a new one using the result, enclosed as you want: ie, "[^" + result + "]".
But Fred's right. This doesn't sound like a good use of regex to me. If it was me, I'd just trawl through the String and bang each Character I find into a LinkedHashSet. Probably quicker than a regex too.
Winston
|
Isn't it funny how there's always time and money enough to do it WRONG?
|
 |
alex gorn
Greenhorn
Joined: Nov 15, 2012
Posts: 5
|
|
Winston Gutkowski wrote:
and how to make that construction usable.
Simple. Find your first pattern, and then create a new one using the result, enclosed as you want: ie, "[^" + result + "]".
thanks, i've got the lesson
Winston Gutkowski wrote:
I wouldn't stake my life that it can't be done though.
probably me too)
|
 |
 |
|
|
subject: regexp: how to make negation of a variable which saves a group number
|
|
|