标签后首字母大写

Capitalizing the first letter after a tag

我正在尝试想出一个搜索和替换方法来将标签后的第一个字母大写,但我没有成功。

我正在使用 Notepad++ 的正则表达式模式。

/<p>\s*(.){1}/

这将匹配一个 <p> 标记,后跟任何类型的空格零次或多次,后跟任何字符 1 次,它会记住第 1 个字符,以便您稍后可以使用它来将其转换为大写.

在Notepad++中,在查找和替换对话框中启用正则表达式模式,然后查找:

(?<=<p>)(.)

并替换为:

\U

说明要匹配的模式:

(?<=a)b   # A positive lookbehind, i.e. match all b that immediately follow a, but
          #   don't match the "a" itself.
(.)       # Find any character (i.e. "."), and capture it.
(?<=a)(.) # Find any character that immediately follows a, and capture it.

和替换:

   # The first captured substring in each match.
\Ux  # Convert x to upper case.
\U # Convert the first captured substring in each match to upper case.

请注意,这会尝试将第一个 字符 转换为大写。如果 <p> 和您想要大写的字母之间可能有其他非字母字符,您可以使用模式:

(?<=<p>)([^A-Za-z]*)(.) 

# [^x]       Matches any character that is not x.
# [^A-Za-z]  Matches any character that is not one of the upper case 
#              or lower case letters.
# x*         Matches zero or more consecutive x.
# [^A-Za-z]* Matches zero or more consecutive characters that are not
#              upper case or lower case letters.

并替换为

\U # The first captured substring (any non-letter characters
       #   that immediately follow <p>) followed by the second captured
       #   substring (the first letter that appears after <p>), which 
       #   is converted to upper case.

要找到的模式说:"match (and capture, in capture group 1) any non-letter characters that immediately follow <p>, and then match (and capture, in capture group 2) the first character that immediately follows the non-letter characters (which must, of course, be the letter we want to ensure is upper case)"。请注意,因为我们使用 *,所以当 <p> 后面没有非字母字符时也会产生匹配,在这种情况下,捕获组 1 将只包含一个空字符串。