Regular Expressions 101

Community Patterns

1

Chinese Digits

Created·2024-01-05 07:56
Updated·2024-02-06 07:02
Flavor·PCRE (Legacy)
Match Chinese Digits less than 1×10^16, such as “一千两百三十四万”、“八萬点七六五”、“玖仟玖佰玖拾玖万玖仟玖佰玖拾玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖点玖玖玖玖玖玖玖玖玖玖玖玖玖玖玖玖”,Upper and lower case Chinese can be mixed, but Chinese numbers and English numbers cannot be mixed. Illegal numbers will not be matched. For example: “两十六” will not be matched, as the correct one should be “二十六”,In general Chinese, “两” and “十” are not used together; “两千零零六” will not be matched, as the correct one should be “两千零六”,as consecutive "零" in the integer part of Chinese numbers are illegal. It need a regex engine that supports the functionality of matching an expression defined in a named capture group, such as "(?[a-z]+)\d+(&letter)". 用于匹配小于1×10^16的中文数字,例如:“一千两百三十四万”、“八萬点七六五”、“玖仟玖佰玖拾玖万玖仟玖佰玖拾玖亿玖仟玖佰玖拾玖万玖仟玖佰玖拾玖点玖玖玖玖玖玖玖玖玖玖玖玖玖玖玖玖”,大小写中文数字可以混用,中文数字与英文数字不可以混用。 不合法的中文数字不会被匹配,例如:“两十六”、“两十六万”不会被匹配,因为中文习惯中不将“两”与“十”连用;“两千零零六”不会被匹配,因为其中有连续的零。 需要引擎支持引用已定义组的表达式,例如:"(?[a-z]+)\d+(&letter)"。
Submitted by anonymous

Community Library Entry

1

Regular Expression
Created·2023-08-31 11:08
Updated·2023-08-31 14:32
Flavor·Java

"
^(?<year>\d{4})[-\/](?<month>0[1-9]|1[0-2])[-\/](?<day>0[1-9]|[1-2][0-9]|3[0-1])(?:[T\s](?:(?<hour>0[0-9]|1[0-9]|2[0-4]):(?<minute>\d{2}):(?<second>\d{2})(?:\.(?<nano>\d+))?))?(?:(?<offset>[Zz]|(?:[+-])(?:[01]\d|2[0-3])(?::?[0-5]\d)?)?)$
"
gm
Open regex in editor

Description

This is still a working in progress

Need to do Unit Tests and search for more use cases

Match partial cases of 8601 such as:

  • missing offset
  • missing time
  • only date and offset
  • nano present or not (and being from 1 digit to 9 digits)

Also properly captures the data by capturing only: year, month, date, hour, minute, second, nano and offset (be it 'Z' or '+02:00' or' +0200')

Submitted by jpmand