• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

Regex with xsd

Status
Not open for further replies.
Hello everyone. I have started working with regex and i was wondering if there is a way to simplify this expression. It is currently working. I just think there would be a way to simplify it.
I have been using this site for help on how to make it faster. http://regex101.com/

Here is my regex
Code:
^(([a-zA-Z]{2,}|[a-zA-Z]{2,}( [a-zA-Z]{2,}| [0-9]{1,})))( \/ [a-zA-Z]{2,}|[a-zA-Z]{2,}( [a-zA-Z]{2,}| [0-9]{1,}))*$

Here is the list of test string that should and should not match.
Code:
Matches:
example
example asd / example
example / example
example / example / example / example
example / example 343345 / example 2 / example
triggered
example 3
example 3 / example 3
example / example 3

Non-matches:
example / example /
example /  /
1 / a
a
123
1

Thanks for anyone that helps.
 
What is the purpose?

From the samples above, it looks to me like what you want is actually a string split, in which case you should use a string split and not a regular expression.

As i said above this is for an xsd file. ( XML Schema)
It is used to make sure the nodes in the Xml are formatted correctly.
Can't use string split in xsd.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
In that case use a XML parser (validator?). You can't parse markup languages with regular expressions, they are on a separate level (heck if I remember the correct term, something with ring).

If you choose to keep using the regex above, then you should support multiple spaces with \s+, the range 0-9 can be written as \d, and {1,} can be replaced with a plus sign.
Finally, look into the look-behind operator ((?<EXPRESSION)), it fits your purpose.
 
Status
Not open for further replies.
Top