0

I have to handle a particular validation via regex in xml.

The user has to enter an ID in which the first four positions should only contain Latin characters (including accents), but no digits, characters from other alphabets, special characters or spaces.

I don't really understand what does "Latin character including accents" means here.

dbank
  • 1,173
  • 1
  • 17
  • 29
user3756951
  • 45
  • 1
  • 6
  • Are you asking us to clarify the validation you're supposed to do? – mash Mar 09 '15 at 05:12
  • Yes. First of all i am not very clear with what does accents mean here.Secondly, if we have to perform regex validation in xml then how will we do that. – user3756951 Mar 09 '15 at 05:23
  • "Latin" could mean a number of things here. I think I would interpret your requirement as being a Unicode character that is in character class L (letter) and is also in one of the blocks 0-x024F or 1E00-1EFF. But the person who wrote this requirement might have meant something different, for example they might have meant "Latin-1", which is the Western European characters in the range 0-xFF. So I would start by getting clarification of the requirement. – Michael Kay Mar 09 '15 at 10:25
  • The other thing that's not clear is what regex dialect you are using. Is it a Java regex? or an XSD regex? They are different. – Michael Kay Mar 09 '15 at 10:27
  • I have got clarification regarding the requirements. It should accept these Latin accents àèìòùÀÈÌÒÙáéíóúýÁÉÍÓÚâêîôûÂÊÎÔÛãñõÃÑÕäëïöüÄËÏÖÜçÇߨøÅ寿œ or A-Z or a-z at the first 4 poistions. The regex should be XML schema regular expression. – user3756951 Mar 09 '15 at 10:51
  • Can anybody help in achieving the regex in xml – user3756951 Mar 09 '15 at 15:31
  • See if these links help: http://stackoverflow.com/a/26900132/4595816 and http://www.regular-expressions.info/unicode.html – dbank Mar 10 '15 at 11:36

1 Answers1

0

JAVA REGEX

Java provides the java.util.regex package for pattern matching with regular expressions. Java regular expressions are very similar to the Perl programming language and very easy to learn.

Pattern Class: A Pattern object is a compiled representation of a regular expression. The Pattern class provides no public constructors. To create a pattern, you must first invoke one of its public static compile methods, which will then return a Pattern object. These methods accept a regular expression as the first argument.

Matcher Class: A Matcher object is the engine that interprets the pattern and performs match operations against an input string. Like the Pattern class, Matcher defines no public constructors. You obtain a Matcher object by invoking the matcher method on a Pattern object.

PatternSyntaxException: A PatternSyntaxException object is an unchecked exception that indicates a syntax error in a regular expression pattern.

example

// String to be scanned to find the pattern.
  String line = "This order was placed for QT3000! OK?";
  String pattern = "(.*)(\\d+)(.*)";

  // Create a Pattern object
  Pattern r = Pattern.compile(pattern);

  // Now create matcher object.
  Matcher m = r.matcher(line);
P.JAYASRI
  • 358
  • 2
  • 18