notepad ++正则表达式删除标记内部/之间的空白并按字母顺序排序

时间:2019-03-17 12:44:09

标签: notepad++

我使用myinterest =“([^”] *)“并替换为myinterest =” \ L \ 1 \ text“以使文本变为小写并在其后添加“ text”,但是我如何还可以删除其中的不需要的空间标签吗?我试过\ 1但不起作用

编辑:尝试“查找内容”     (?:\ bmyinterest =“ | \ G)\ K \ h *([^” \ s>] +)(\ h *“)? “用。。。来代替”     \ L $ 1(?2text“:)

这可以删除空格和小写字母,但是如何更改以使其按字母顺序排序?我在记事本++中尝试,但是我不知道如何从myinterest =“”

中的单词进行排序

示例数据:

myinterest="footballtext">random Name</></endofothertag> 
myinterest="sportsandflowerstext">random Name</></endofothertag>
myinterest="horseridingtext">random Name</></endofothertag>
myinterest="bowlingtext">random Name</></endofothertag>

应为:

myinterest="bowlingtext">random Name</></endofothertag>
myinterest="footballtext">random Name</></endofothertag>
myinterest="horseridingtext">random Name</></endofothertag>
myinterest="sportsandflowerstext">random Name</></endofothertag>

2 个答案:

答案 0 :(得分:0)

您没有提供示例数据,所以我即兴创作了

您可以尝试

查找内容:myinterest="\s*([^"]*?)\s*"

替换为:myinterest="\L\1\Etext"

它将改变这一点:

myinterest="   Sports and Flowers   "
myinterest="Sports and Flowers"
myinterest="SPORT and wine"
myinterest=" TV "
myinterest="   MOVIES   "
myinterest=" food    "
myinterest="   running"
myinterest="play   "

...进入此:

myinterest="sports and flowerstext"
myinterest="sports and flowerstext"
myinterest="sport and winetext"
myinterest="tvtext"
myinterest="moviestext"
myinterest="foodtext"
myinterest="runningtext"
myinterest="playtext"

答案 1 :(得分:0)

  • Ctrl + H
  • 查找内容:(?:\bmyinterest="|\G)\K\h*([^"\s>]+)(\h*")?
  • 替换为:\L$1(?2text":)
  • 检查环绕
  • 检查正则表达式
  • 全部替换

说明:

(?:                 # non capture group
    \b              # word boundary
    myinterest="    # literally
  |                 # OR
    \G              # restart from last match position
)                   # end group
\K                  # forget all we have seen until this position
\h*                 # 0 or more horizontal spaces
([^"\s>]+)          # group 1, 1 or more non quote space or >
(\h*")?             # group 2, 0 or more horizontal spaces and a quote, optional

替换:

\L$1                # lowercase group 1
(?2                 # conditional replacement, if group 2 exists
    text"           # add text and quote
    :               # else, nothing
)                   # end condiitonal

给出:

myinterest="football"

myinterest="Sports and Flowers"

myinterest="football">random Name</></endofothertag> 
myinterest="Sports and Flowers">random Name</></endofothertag> 

给定示例的结果

myinterest="footballtext"

myinterest="sportsandflowerstext"

myinterest="footballtext">random Name</></endofothertag> 
myinterest="sportsandflowerstext">random Name</></endofothertag> 

屏幕截图:

enter image description here