作者:绿色风
分类:
时间:2022-08-18
浏览:191
楼主 kevinchengcw |
以下内容是我从网上得到的文本经常遇到的情况:- Four Cheese Ravioli
- Ingredients
- Ravioli Dough: 2 cups all-purpose flour 1 pinch salt 1 teaspoon olive oil 2 eggs 1 1/2 tablespoons water
- Ravioli Filling: 1 (8 ounce) container ricotta cheese 1 (4 ounce) package cream cheese, softened 1/2 cup shredded mozzarella cheese 1/2 cup provolone cheese, shredded 1 egg 1 1/2 teaspoons dried parsley
- Pesto-Alfredo Cream Sauce: 2 tablespoons olive oil 2 cloves garlic, crushed 3 tablespoons prepared basil pesto
- sauce 2 cups heavy cream 1/4 cup grated Parmesan cheese 1 (24 ounce) jar marinara sauce
- Egg Wash: 1 egg 1 tablespoon water
请用正则将文本变成下面这样:- Four Cheese Ravioli
- Ingredients
- Ravioli Dough:
- 2 cups all-purpose flour
- 1 pinch salt
- 1 teaspoon olive oil
- 2 eggs
- 1 1/2 tablespoons water
- Ravioli Filling:
- 1 (8 ounce) container ricotta cheese
- 1 (4 ounce) package cream cheese, softened
- 1/2 cup shredded mozzarella cheese
- 1/2 cup provolone cheese, shredded
- 1 egg
- 1 1/2 teaspoons dried parsley
- Pesto-Alfredo Cream Sauce:
- 2 tablespoons olive oil
- 2 cloves garlic, crushed
- 3 tablespoons prepared basil pesto sauce
- 2 cups heavy cream
- 1/4 cup grated Parmesan cheese
- 1 (24 ounce) jar marinara sauce
- Egg Wash:
- 1 egg
- 1 tablespoon water
注意:正则表达式须对此类型通用。
答题有效期15天。
2010-12-18 开帖: 参考答案:- Sub test1()
- Dim RegEx As Object, N&, Str$
- Set RegEx = CreateObject("vbscript.regexp")
- With RegEx
- .Global = True
- .Pattern = "([^\d/(])([\d/\.]+ [^/])"
- End With
- For N = 1 To Cells(Rows.Count, 1).End(3).Row
- Cells(N, 2) = RegEx.Replace(Cells(N, 1).Value, "$1" & vbNewLine & "$2")
- Next N
- Set RegEx = Nothing
- End Sub
|
2楼 liuguansky |
正则练习.rar 还没人回帖啊,我回一个吧.
- Sub justtest()
- Dim Regex As Object, str1$, mat
- Set Regex = CreateObject("vbscript.regexp")
- With Regex
- .Global = True
- .MultiLine = True
- .Pattern = "([1-9]+(\s[1-9]+\/[1-9]+|\/[1-9]+|\s\([1-9]+\s\w+\))?)" '(\s\w+)+?)(?=[1-9])"
- str1 = Cells(1, 1).Value
- Cells(1, 2) = .Replace(str1, vbCrLf & "$1")
- 'Debug.Print .Replace(str1, vbCrLf & "$1")
- End With
- End Sub
|
3楼 xyh9999 |
k哥,你的原文件有一处多了个换行符,请检查一下。 xyh9999Test.rar
- Function xyh9999k()
- cc = LqcFileToStr(ThisWorkbook.Path & "\k.txt")
- Set RegEx = CreateObject("VBscript.RegExp")
- With RegEx
- .MultiLine = False
- .Global = True
- .IgnoreCase = True
- .Pattern = "(\s+)(\b\d\S*?\b\s+?\S)"
- End With
- Set Arr = RegEx.Execute(cc)
- tt = RegEx.Replace(cc, "$1" & Chr(13) & "$2")
- Set RegEx = Nothing
- xyh9999k = tt
- End Function
运行结果:
- Four Cheese Ravioli
- Ingredients
- Ravioli Dough:
- 2 cups all-purpose flour
- 1 pinch salt
- 1 teaspoon olive oil
- 2 eggs
- 1 1/2 tablespoons water
- Ravioli Filling:
- 1 (8 ounce) container ricotta cheese
- 1 (4 ounce) package cream cheese, softened
- 1/2 cup shredded mozzarella cheese
- 1/2 cup provolone cheese, shredded
- 1 egg
- 1 1/2 teaspoons dried parsley
- Pesto-Alfredo Cream Sauce:
- 2 tablespoons olive oil
- 2 cloves garlic, crushed
- 3 tablespoons prepared basil pesto
- sauce
- 2 cups heavy cream
- 1/4 cup grated Parmesan cheese
- 1 (24 ounce) jar marinara sauce
- Egg Wash:
- 1 egg
- 1 tablespoon water
|
4楼 xyh9999 |
请k哥再发些练习,正好这几天复习过,做做测试以便巩固一下。 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一