I need to create a regular expression that matches an ID that has a specific format. The ID always begins with “OR” followed by 4 digits, then a dash, then another number that can be of any length. Examples of valid matches are:
OR1581-2
OR0057-101
OR0000-5312
OR3450-17371
Thanks!
Try
^OR\d{4}-\d+$.^matches the beginning of the string or line.ORis not a special sequence and will match only those two characters in order.\dmatches any digit, and{4}is shorthand for listing the preceding group (the digit) exactly four times.-is not a special character and will match only the hyphen.\dmatches any digit again, and the+requires the preceding group (the digit) to occur one or more times.$matches the end of the string or line.