Click here to Skip to main content
15,908,775 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here i want to ask a question 'bout a regular expression,
as the same like the question title, i want to create a Regex pattern from a string that contains $XXXX or $XXXX-Z (the X and Z is ignoreCase, it can be uppercase, or lowercase),

example of the string is :

* here is the example of string contains $XYZA
* here is the second example of string contains $XYZA-B

can somebody help me please, i need it very quick.
thanks..
Posted

^\$[a-zA-Z]{4}(\-[a-zA-Z])?$
 
Share this answer
 
If you want to match the whole string exactly same as pattern i.e. [$XXXX] or [$XXXX-X] then you can go for it.

JavaScript
^\$([a-z|A-Z]{4})(-[a-z|A-Z]{1})*$


Else you can check below to search for matches similar to your pattern in long string.

JavaScript
\$([a-z|A-Z]{4})(-[a-z|A-Z]{1})*


Hope this will help you.. :)
 
Share this answer
 
thanks for your solution all, it's now work on my website. :D
 
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