C 整数リテラルを決定する

網膜 0.8.2、60 59 バイト

i`^(0[0-7]*|0x[\da-f]+|[1-9]\d*)(u)?(l)?(?-i:\3?)(?(2)|u?)$

オンラインでお試しください!リンクにはテストケースが含まれています。編集:@FryAmTheEggMan のおかげで 1 バイト節約できました。説明:

i`

大文字と小文字を区別せずに一致します。

^(0[0-7]*|0x[\da-f]+|[1-9]\d*)

8 進数、16 進数、または 10 進数のいずれかで開始します。

(u)?

オプションの符号なし指定子。

(l)?

オプションの長さ指定子。

(?-i:\3?)

必要に応じて、長さ指定子の大文字と小文字を区別して繰り返します。

(?(2)|u?)$

unsigned 指定子がまだない場合は、リテラルの末尾の前に、オプションの指定子の別の機会があります。


Perl 5 -p65 61バイト

@NahuelFouilleul は 4 バイトを剃った

$_=/^(0[0-7]*|0x\p{Hex}+|[1-9]\d*)(u?l?l?|l?l?u?)$/i*!/lL|Ll/

オンラインで試してみてください!


Java 8 / Scala ポリグロット、89 79 バイト

s->s.matches("(?!.*(Ll|lL))(?i)(0[0-7]*|[1-9]\\d*|0x[\\da-f]+)(u?l?l?|l?l?u?)")

@NahuelFouilleul のおかげで -10 バイト

Java 8 でオンラインで試してみてください。
Scala でオンラインで試してみてください (=> を除く) -> の代わりに - @TomerShetah に感謝 ).

説明:

s->           // Method with String parameter and boolean return-type
  s.matches(  //  Check whether the input-string matches the regex
    "(?!.*(Ll|lL))(?i)(0[0-7]*|[1-9]\\d*|0x[\\da-f]+)(u?l?l?|l?l?u?)")

正規表現の説明:

Java では、String#matches メソッドは暗黙的に先頭と末尾に ^...$ を追加します 文字列全体に一致するため、正規表現は次のようになります:

^(?!.*(Ll|lL))(?i)(0[0-7]*|[1-9]\d*|0x[\da-f]+)(u?l?l?|l?l?u?)$
 (?!         )     # The string should NOT match:
^   .*             #   Any amount of leading characters
      (     )      #   Followed by:
       Ll          #    "Ll"
         |lL       #    Or "lL"
                   # (Since the `?!` is a negative lookahead, it acts loose from the
                   #  rest of the regex below)

 (?i)              # Using case-insensitivity,
^    (             # the string should start with:       
       0           #   A 0
        [0-7]*     #   Followed by zero or more digits in the range [0,7]
      |            #  OR:
       [1-9]       #   A digit in the range [1,9]
            \d*    #   Followed by zero or more digits
      |            #  OR:
       0x          #   A "0x"
         [     ]+  #   Followed by one or more of:
          \d       #    Digits
            a-f    #    Or letters in the range ['a','f'] 
     )(            # And with nothing in between,
              )$   # the string should end with:
        u?         #   An optional "u"
          l?l?     #   Followed by no, one, or two "l"
       |           #  OR:
        l?l?       #   No, one, or two "l"
            u?     #   Followed by an optional "u"

No