正则表达式模式接受逗号和冒号

时间:2021-03-18 11:08:46

I am searching for regex pattern that matches the following String. I am using this regex pattern as,

我正在搜索与以下字符串匹配的正则表达式模式。我正在使用这个正则表达式模式,

^;[A-za-z0-9,:]+

Above regex doesn't matches the following. I am looking for all given string to be matched with regex pattern.

以上正则表达式与以下内容不匹配。我正在寻找所有给定的字符串与正则表达式模式匹配。

:a123,234,444:322 //String started with semicolon and values are separated with comma and colon ;123,A234:123;123,345,456:999,456 // Above case with repeated condition

:a123,234,444:322 //字符串以分号开头,值以逗号和冒号分隔; 123,A234:123; 123,345,456:999,456 //重复条件以上情况

;;123,345,C555:123 //String started with double semicolon

;; 123,345,C555:123 //字符串以双分号开头

Can anyone provide regex pattern that matches above string.

任何人都可以提供匹配上面的字符串的正则表达式模式

2 个解决方案

#1


0  

This one

[;:]+[A-za-z0-9,;:]+

will work for all three you want, see online on regex101.

将适用于您想要的所有三个,请在regex101上在线查看。

  1. [;:]+: Started with one or more ; or : .
  2. [;:] +:从一个或多个开始;要么 : 。

  3. [A-za-z0-9,;:]+: You miss' a : here.
  4. [A-za-z0-9,;:] +:你想念'a:这里。

#2


0  

You can match the above with this regex

您可以将上述内容与此正则表达式进行匹配

^;+[A-za-z0-9,;:]+

Modifications:

  1. ;+ will match 1 or more semicolons
  2. ; +将匹配1个或更多分号

  3. colon : has been added in characters you want to match
  4. 冒号:已添加到您想要匹配的字符中

#1


0  

This one

[;:]+[A-za-z0-9,;:]+

will work for all three you want, see online on regex101.

将适用于您想要的所有三个,请在regex101上在线查看。

  1. [;:]+: Started with one or more ; or : .
  2. [;:] +:从一个或多个开始;要么 : 。

  3. [A-za-z0-9,;:]+: You miss' a : here.
  4. [A-za-z0-9,;:] +:你想念'a:这里。

#2


0  

You can match the above with this regex

您可以将上述内容与此正则表达式进行匹配

^;+[A-za-z0-9,;:]+

Modifications:

  1. ;+ will match 1 or more semicolons
  2. ; +将匹配1个或更多分号

  3. colon : has been added in characters you want to match
  4. 冒号:已添加到您想要匹配的字符中