Prompt Title: regex

Created 8 months ago
Votes 0
Views 222 times
0
Human: <div class="">create me regex to validate string if it's vehicle vin code or string that starts from "temp-"</div>
ChatGPT:

Certainly! Here's a regular expression that validates if a string is either a vehicle VIN code or starts with "temp-":

css
^(?=.*[A-HJ-NPR-Z0-9]{17}$)(temp-.+|(?![IOQ])[A-HJ-NPR-Z0-9]{17})$

Explanation:

  • ^ asserts the start of the string.
  • (?=.*[A-HJ-NPR-Z0-9]{17}$) is a positive lookahead assertion ensuring that the string contains exactly 17 characters from the set [A-HJ-NPR-Z0-9], which are the characters used in VIN codes.
  • (temp-.+|(?![IOQ])[A-HJ-NPR-Z0-9]{17}) checks for either:
    • temp- followed by any character (.+ matches one or more characters).
    • Or a string of exactly 17 characters from the set [A-HJ-NPR-Z0-9], excluding the characters I, O, and Q, which are not used in VIN codes.
  • $ asserts the end of the string.

This regex should effectively validate if a string is either a vehicle VIN code or starts with "temp-".

avatar
me
Shared 41 prompts
Created 8 months ago

Leave a Comment

Related Tag Prompts

94
0
151
0
Docker Pro
1 year ago 2023-01-29 06:08:59 AIPRM
308
0
MySQL Marvel
1 year ago 2023-02-13 00:05:32 AIPRM
260
0
Ansible Expert
1 year ago 2023-02-01 09:23:50 AIPRM
193
0
PostgreSQL Pro
1 year ago 2023-02-07 03:45:19 AIPRM
114
0
270
1
Dockerize me
1 year ago 2023-02-17 08:27:58 Chad Thompson-Smith