如何创建以下内容的正则表达式:
我有一长串的产品名称和 SKU 列表,以 TAB 分隔。
Name Nameson[TAB]SKU
Name2 Nameson 2[TAB]SKU2
我需要以下文本:
从
Joey's "Special" Name of the Beverage ProductNA5434
Öetkär's Burgér/Pizza Food123
到
joeys-special-name-of-the-beverage-productna5434
oetkars-burger-pizza-food123
因此,操作如下:
用安全版本替换欧洲区域特殊字符例如:
ä,á,å etc
=>a
ö etc
=>o
e,é,è etc
=>e
ú,ù,ü etc
=>u
- 等等。
仅替换以下符号:
Spacebar Tab , . / \ _
=>-
例如完全删除更多特殊符号
'´"?!@£$€{[]}
等等。(可选)将所有文本变为小写
非常感谢你的帮助!
答案1
- Ctrl+H
- 找什么:
([àäâ])|([éèëê])|([îï])|([öôò])|([ùûü])|([\h,./-]+)|[^a-z0-9\r\n]+
- 用。。。来代替:
(?1a:(?2e:(?3i:(?4o:(?5u:(?6-))))))
- 打钩 环绕
- 选择 正则表达式
- 取消勾选
. matches newline
- Replace all
解释:
([àäâ]) # group 1, letter "a" with diacritics, you can add other if needed
| # OR
([éèëê]) # group 2, letter "e" with diacritics, you can add other if needed
| # OR
([îï]) # group 3, letter "i" with diacritics, you can add other if needed
| # OR
([öôò]) # group 4, letter "o" with diacritics, you can add other if needed
| # OR
([ùûü]) # group 5, letter "u" with diacritics, you can add other if needed
| # OR
([\h,./-]+) # group 6, spaces, comma ...
| # OR
[^a-z0-9\r\n]+ # any character that is not letter, digit or linebreak
替代品:
(?1 # if group 1 exists (i.e; found à, â, ä, ...)
a # replace with a
: # else
(?2 # if group 2 exists
e # replace with e
: # else
(?3 # if group 3 exists
i # replace with i
: # else
(?4 # if group 4 exists
o # replace with o
: # else
(?5 # if group 5 exists
u # replace with u
: # else
(?6 # if group 6 exists
- # replace with -
)))))) # endifs
截图(之前):
截图(之后):
将整个文本变为小写:
- 全选Ctrl+A
- Ctrl+u