タグ

regexに関するnonyleneのブックマーク (4)

  • Runaway Regular Expressions: Catastrophic Backtracking

    Consider the regular expression (x+x+)+y. Before you scream in horror and say this contrived example should be written as xx+y or x{2,}y to match exactly the same without those terribly nested quantifiers: just assume that each “x” represents something more complex, with certain strings being matched by both “x”. See the section on HTML files below for a real example. Let’s see what happens when y

  • BBC Radio 4 - Today - Puzzle for Today

    This is no ordinary crossword! Instead of a word or phrase, each clue is a regular expression (or a ‘regex’). To complete the puzzle, find the letter matching both the horizontal and vertical regex for each square. The Internet has many regex resources, allowing you to learn and practice online – but here are a few pointers to get you started: Characters in square brackets [LIKETHIS] are 'characte

    BBC Radio 4 - Today - Puzzle for Today
  • 正規表現によるバリデーションでは ^ と $ ではなく \A と \z を使おう

    正規表現によるバリデーション等で、完全一致を示す目的で ^ と $ を用いる方法が一般的ですが、正しくは \A と \z を用いる必要があります。Rubyの場合 ^ と $ を使って完全一致のバリデーションを行うと脆弱性が入りやすいワナとなります。PerlPHPの場合は、Ruby程ではありませんが不具合が生じるので \A と \z を使うようにしましょう。 はじめに 大垣さんのブログエントリ「PHPer向け、Ruby/Railsの落とし穴」には、Rubyの落とし穴として、完全一致検索の指定として、正規表現の ^ と $ を指定する例が、Ruby on Rails Security Guideからの引用として紹介されています。以下の正規表現は、XSS対策として、httpスキームあるいはhttpsスキームのURLのみを許可する正規表現のつもりです。 /^https?:\/\/[^\n]+$/

  • 正規表現メモ

    \x{} \pは後続する名前が表すクラス(プロパティ、スクリプト、ブロック)に属する文字にマッチし、 \Pは後続する名前のクラスに属さない文字にマッチします。 クラスの名前が一文字のときはブレースを省略できます。 クラス名の前に^を置くことにより否定形の指定を行うことも可能です。 Perl 5.8 での変更点 Perl5.8以降(5.6でも使えたようですが)では \pや\Pで始まるプロパティ指定に標準Unicode属性を使うこともできます。 詳しくは perlunicode perlunicode - Perl における Unicode サポート を参照してください。 日語による説明が Unicodestandard にもあります。 Perl 5.8以降ではユーザーが任意のプロパティを作成することができます (IsまたはInを必ず前置)。 詳しくは perlunicode perluni

  • 1