3

indexOfの head セクションを呼び出していjQueryます。font-weight:boldCSS にプロパティが含まれているかどうかを確認したい。問題は、そのプロパティに 4 つの変更を加えることができるということです。

  1. font-weight:bold
  2. font-weight: bold
  3. font-weight :bold
  4. font-weight : bold

正規表現を使用してこれを一致させるにはどうすればよいですか?

4

5 に答える 5

4

これを試して

\b(?:font-weight\s*:[^;\{\}]*?\bbold)\b

または使用する方が良いでしょう:

\b(?:font-weight[\s*\\]*:[\s*\\]*?\bbold\b)

説明

\b                # Assert position at a word boundary
(?:               # Match the regular expression below
   font-weight       # Match the characters “font-weight” literally
   [\s*\\]           # Match a single character present in the list below
                        # A whitespace character (spaces, tabs, and line breaks)
                        # The character “*”
                        # A \ character
      *                 # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
   :                 # Match the character “:” literally
   [\s*\\]           # Match a single character present in the list below
                        # A whitespace character (spaces, tabs, and line breaks)
                        # The character “*”
                        # A \ character
      *?                # Between zero and unlimited times, as few times as possible, expanding as needed (lazy)
   \b                # Assert position at a word boundary
   bold              # Match the characters “bold” literally
   \b                # Assert position at a word boundary
)

お役に立てれば。

于 2012-05-29T04:50:13.640 に答える
2

整数700として設定するfont-weight:bold;ことも、文字列の範囲をかなり一致するように拡張する省略表記を使用して設定することもできます。font

\b(?:font.*?:[^;]*?\b(bold|700))\b

いじる

于 2012-05-29T05:06:04.160 に答える
0

そのために正規表現を使用することはできません。CSSには次のような文字列が含まれる場合があります

.foo{ content: "font-weight:bold;" }

適切なパーサーが必要です。幸いなことに、ブラウザーには 1 つあり、個々の CSS ルールにアクセスするためのAPIを提供します。

于 2012-05-29T05:32:08.590 に答える
0

これを試して:

/font-weight\: bold|font-weight\:bold|font-weight \:bold|font-weight \: bold/
于 2012-05-29T04:59:07.537 に答える
0

これを試して:

RegularExpressionValidator.ValidationExpression = "font-weight\s?:\s?bold"
于 2012-05-29T05:03:57.233 に答える