Results 1 to 5 of 5

Thread: Regex problem

  1. #1
    Nimyz is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default Regex problem

    Hi,

    Is it possible to make a regular expression so that a certain character can only be used a 2 times throughout the whole string? It doesn't work with quantifiers because those ensure you that a certain character can't be used a certain amount of times in a pattern and not in a whole string.

    Thanks in advance!

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    something like this?

    rerfrgrxgsthhgbdxdg

    Yes, it's possible. In may ways you can validate that.

  3. #3
    Nimyz is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default

    Really? How? Because I searched for 2 hours and I didn't find a solution to it :s
    You don't want to give a hint perhaps? :-)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Nimyz View Post
    Really? How? Because I searched for 2 hours and I didn't find a solution to it :s
    You don't want to give a hint perhaps? :-)
    Java Code:
    ^[^x]*x?[^x]*x?[^x]*$
    This regexp recognizes at most two x's in a line. If you want exactly two x's remove the question marks.

    kind regards,

    Jos

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Please Help - Regex
    By BeeGee in forum Advanced Java
    Replies: 0
    Last Post: 04-28-2010, 05:28 PM
  2. Help with regex
    By SteroidalPsycho in forum New To Java
    Replies: 2
    Last Post: 03-29-2010, 12:40 AM
  3. Using regex
    By SteroidalPsycho in forum New To Java
    Replies: 0
    Last Post: 03-28-2010, 11:07 PM
  4. Multiline Regex
    By zriggle in forum New To Java
    Replies: 1
    Last Post: 02-26-2009, 04:49 AM
  5. regex problem - allowing optional space
    By Norm in forum Advanced Java
    Replies: 26
    Last Post: 10-06-2008, 04:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •