Capitalizing the first letter after a tag

回眸只為那壹抹淺笑 提交于 2019-12-06 06:08:06

In Notepad++, enable regex mode in the Find and Replace dialog box, then find:

(?<=<p>)(.)

and replace with:

\U\1

To explain the pattern to be matched:

(?<=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.

And the replacement:

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

Note that this attempts to convert the first character to upper case. If there might be other non-letter characters between the <p> and the letter that you want capitalised, you could the pattern:

(?<=<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.

and replace with

\1\U\2 # 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.

The pattern to be found says: "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)". Note that because we use *, a match will also result when there are no non-letter characters following <p>, in which case capture group one will just hold an empty string.

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

This will match a <p> tag followed by any kind of whitespace zero or more times, followed by any character 1 time and it will remember the 1 character so that you can use it later to turn it to uppercase.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!