简体   繁体   中英

Regular expression with Azure DevOps task extension

We're updating our azure virtual machine task extension with disk management. A multiline field to let user provide label, letter and size of their data disks with newline and semicolons to separate items and disks. Like this:

"Database Disk";F;30

"Temp Database Disk";G;30

"Logs Database";H;15E

Here is task.json:

{
  "name": "NewDataDisks",
  "type": "multiLine",
  "label": "Data Disks",
  "required": false,
  "groupName": "Disks",
  "visibleRule": "AddDataDisk = true",
  "defaultValue": "\"Database Disk\";F;30\n\"Temp Database Disk\";G;30\n\"Logs Database\";H;15",
  "helpMarkDown": "Provide list of data disks with disk label, mount letters and disk capacity separated by a semicolon :\n\n \"Database Disk\";F;30\n\"Temp Database Disk\";G;30\n\"Logs Database\";H;15 \n\n Each virtual machine size has a max of data disks attached which can't be check in here. During release execution, a check will be done.",
  "validation": {
    "expression": "isMatch(value, '(^\"[a-z A-Z]+\";[a-zA-Z]{1};([1-9]+[0-9]+|[1-9]+)$)','Multiline')",
    "message": "[Enter a valid datadisks list](https://regex101.com/r/WeDgsJ/1)"
  }
}

Problem is validation will pass if at least one line is matching. But I'd like a full match for every line but I struggle finding how with regex. Any help will be appreciated.

Thanks.

You can remove the 'Multiline' option (since you need to treat the string as a whole text, not as a line-per-line text) and use

'^"[a-z A-Z]+";[a-zA-Z];[1-9][0-9]*(?:\r?\n"[a-z A-Z]+";[a-zA-Z];[1-9][0-9]*)*$'

Details :

  • ^ - start of string
  • " - a " char
  • [az AZ]+ - one or more ASCII letters or space
  • "; - "; substring
  • [a-zA-Z] - an ASCII letter
  • ; - a semi-colon
  • [1-9][0-9]* - a non-zero digit and then zero or more digits
  • (?: - start of a non-capturing "container" group:
    • \r?\n - CRLF or LF line ending
    • "[az AZ]+";[a-zA-Z];[1-9][0-9]* - same patterns as above
  • )* - end of the group, repeat zero or more times
  • $ - end of string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM