Click here to Skip to main content
15,889,609 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi Everyone,

Please explain the below regular expression pattern. What characters it allows.
And what is '*' here ?

<xsd:complexType name="NameType">
 <xsd:sequence>
  <xsd:element name="FirstName">
	<xsd:simpleType>
	  <xsd:restriction base="xsd:string">
		 <xsd:maxLength value="16"/>
		  <xsd:pattern value="([A-Za-z0-9'\-] ?)*[A-Za-z0-9'\-]"/>
	    </xsd:restriction>
	  </xsd:simpleType>
  </xsd:element>
 </xsd:sequence>
</xsd:complexType>


Please guide me how to understand [A-Za-z0-9'\-] ?)*[A-Za-z0-9'\-] pattern.

What I have tried:

As per my assumption it allows A-Z, a-z ,0-9 and spacial characters like Back slash,
Single Quote, and Hyphen.
Posted
Updated 14-Jun-17 21:04pm

 
Share this answer
 
Quote:
As per my assumption it allows A-Z, a-z ,0-9 and spacial characters like Back slash,
Single Quote, and Hyphen.

Your RegEx is a little more complex than that, looks like your problem is that you use RegEx without really learning it.
Use last link and paste the RegEx and you will see a nice graph of your RegEx, hope it helps you to understand it.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900