Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex (19,6)的正则表达式_Regex - Fatal编程技术网

Regex (19,6)的正则表达式

Regex (19,6)的正则表达式,regex,Regex,试图编写一个正则表达式函数,不允许保存到我的数据库中的任何不是(19,6)十进制数的内容 因此,9.999可以在68.1234557失败的地方工作。 还需要1234567890123456789.1才能失败。在19个位置中感觉它 还支持负片类似的功能: ^[+-]?\d{,13}(\.\d{,6})?$ 这将匹配: 字符串的开头(^) 可选加号或减号(文字+或-) 零至13位(19-6) 可选的一组: 文字 0到6位 字符串的结尾($) 开始/结束锚定用于禁止在匹配的子字符串之前或之后

试图编写一个正则表达式函数,不允许保存到我的数据库中的任何不是(19,6)十进制数的内容

因此,9.999可以在68.1234557失败的地方工作。 还需要1234567890123456789.1才能失败。在19个位置中感觉它


还支持负片

类似的功能:

^[+-]?\d{,13}(\.\d{,6})?$
这将匹配:

  • 字符串的开头(
    ^
  • 可选加号或减号(文字
    +
    -
  • 零至13位(19-6)
  • 可选的一组:
    • 文字
    • 0到6位
  • 字符串的结尾(
    $
开始/结束锚定用于禁止在匹配的子字符串之前或之后添加其他字符

^\d{,19}(\.\d{,6})?$
如果需要小数点,请执行以下操作:

^\d{,19}\.\d{1,6}$
怎么样:
^(?=^.{1,19}$)\d+(?:\。\d{1,6})?$

说明:

The regular expression:

(?-imsx:^(?=^.{1,19}$)\d+(?:\.\d{1,6})?$)

matches as follows:

NODE                     EXPLANATION
----------------------------------------------------------------------
(?-imsx:                 group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching \n) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  ^                        the beginning of the string
----------------------------------------------------------------------
  (?=                      look ahead to see if there is:
----------------------------------------------------------------------
    ^                        the beginning of the string
----------------------------------------------------------------------
    .{1,19}                  any character except \n (between 1 and
                             19 times (matching the most amount
                             possible))
----------------------------------------------------------------------
    $                        before an optional \n, and the end of
                             the string
----------------------------------------------------------------------
  )                        end of look-ahead
----------------------------------------------------------------------
  \d+                      digits (0-9) (1 or more times (matching
                           the most amount possible))
----------------------------------------------------------------------
  (?:                      group, but do not capture (optional
                           (matching the most amount possible)):
----------------------------------------------------------------------
    \.                       '.'
----------------------------------------------------------------------
    \d{1,6}                  digits (0-9) (between 1 and 6 times
                             (matching the most amount possible))
----------------------------------------------------------------------
  )?                       end of grouping
----------------------------------------------------------------------
  $                        before an optional \n, and the end of the
                           string
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------
OK : 9.999
OK : 123456.123456
KO : 68.1234557
KO : 1234567890123456789.1
用于测试它的perl脚本:

use strict;
use warnings;
use 5.010;

my $re = qr~^(?=^.{1,19}$)\d+(?:\.\d{1,6})?$~;
while(<DATA>) {
    chomp;
    say /$re/ ? "OK : $_" : "KO : $_";
}
__DATA__
9.999
123456.123456
68.1234557
1234567890123456789.1

你试过什么吗?那么
a
应该可以用正则表达式实现吗?正则表达式是用什么语言实现的(bash、python、Ruby等等)?他们确实有点不同…请发布一些代码。在发布问题之前,您需要自己尝试解决方案;这不是一个您可以发布问题描述并等待解决方案的站点,因为您自己没有做任何工作。我尝试使用\d{,13}(\。\d({,6})?但当我试图在正则表达式测试仪上使用它时。它显示不允许9这样的值,但它将匹配25位数字。我认为他最多需要19位数字,小数最多为6位。@t你说得对。小数右边的数字是固定的,所以只能有13位(19-6)小数点左边的数字。这与小数点左边有16位,右边有2位的数字不匹配。@interjay这是正确的
decimal
是一种固定精度的数据类型(至少在MS SQL中是这样,在大多数其他SQL引擎中我都很确定).这意味着总位数为19,其中6位在小数点的右边,13位(19-6)在左边。