• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

regexp: how to make negation of a variable which saves a group number

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
alex gorn
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
language barrier)) english is not my native, sorry

i meant how many different letters are contained in the word..
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
alex gorn
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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)
 
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic