2 Replies Latest reply: Nov 23, 2007 3:08 AM by 807603 RSS

    Regex partial matching

    807603
      I am trying to check user input at every stage to verify that he is typing against a preset pattern. My current implementation is quite simplistic - I take parts of the pattern (from the start to some point) and try to match them against input. Example:
      If all input pattern is \d\d\d and user has input 12, it will be OK since it will match \d\d which is a part of the pattern.
      Obviously there is a problem if the pattern is \d{3}, because no part of it can match 12, although it is OK as partial input.

      Do you have a solution for such an issue? At this stage the only possibility I see is to try to build a String that will fully match the pattern, replace input in it and check (e.g. have 000, replace 12 -> 120 which matched \d{3}). But building such an expression can be time consuming for patterns with bigger samples.

      Thank you for sharing your time and knowledge