正则表达式从字符串中删除单词 [英] Regex to remove word from string

查看:159
本文介绍了正则表达式从字符串中删除单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



需要快速帮助来解决我的问题。我有一个字符串说星期一星期一100。现在我需要从这个字符串中删除星期一,需要输出为Sunday100。



我需要通过正则表达式来完成。你能帮帮我吗。



谢谢,

Simran



我需要Rubular.com中的解决方案,因为它可以按我的工具工作。我不能写替换或使用控制台因为我需要编写正则表达式字符串来操纵值。



目前在Rubular.com

你的正则表达式:

(^。*) - ?(星期一)(。*)$



您的测试字符串:

周日周一100



匹配结果:

周日周一100



比赛团体:

1.周日

2.周一
3. 100



我想在Rubular.com中找到的是:



您的测试字符串:

周日周一100



赛果结果:

星期一,星期一100



赛事小组:

1.星期天100

b / b




任何快速帮助都将受到高度赞赏。



谢谢,

Simran



我的尝试:



(^。*) - ?(星期一)(。*)$



但是这给了我输出

1.星期天

2.星期一

3. 100

Hi Guys,

Need quick help to resolve my issue. I have a string say "Sunday Monday100". Now I need to remove Monday from this string and need output as Sunday100.

I need to do it through regex. Can you guys help me out.

Thanks,
Simran

I need the solution in Rubular.com as that works as per my tool. I can not write replace or use console coz I need to write regex string to manipulate the value.

Currently in Rubular.com
Your regular expression:
(^.*)-?(Monday)(.*)$

Your test string:
Sunday Monday100

Match result:
Sunday Monday100

Match groups:
1. Sunday
2. Monday
3. 100

What I want in Rubular.com is:

Your test string:
Sunday Monday100

Match result:
Sunday Monday100

Match groups:
1. Sunday100



Any quick help will be highly appreciated.

Thanks,
Simran

What I have tried:

(^.*)-?(Monday)(.*)$

but this gives me output as
1. Sunday
2. Monday
3. 100

推荐答案





您的测试字符串:

周日周一100



匹配结果:

星期一星期一100



匹配组:

1.星期天

2.星期一

3. 100



我想要的Rubular.com是:



您的测试字符串:

周一周一100



比赛结果:

星期一星期一100



比赛分组:

1 。星期日100







任何快速帮助都将受到高度赞赏。



谢谢,

Simran



我的尝试:



(^。*) - ?(星期一)(。*)


Your test string:
Sunday Monday100

Match result:
Sunday Monday100

Match groups:
1. Sunday
2. Monday
3. 100

What I want in Rubular.com is:

Your test string:
Sunday Monday100

Match result:
Sunday Monday100

Match groups:
1. Sunday100



Any quick help will be highly appreciated.

Thanks,
Simran

What I have tried:

(^.*)-?(Monday)(.*)






但是这给了我输出

1.星期天

2.星期一

3. 100


but this gives me output as
1. Sunday
2. Monday
3. 100


您确定不需要SPACE吗?

HYPHEN应该是空格吗?



Are you sure you don't need the SPACE?
Is that HYPHEN supposed to be a SPACE?

System.Console.WriteLine ( System.Text.RegularExpressions.Regex.Replace ( "Sunday Monday100" , "(^.*)-?(Monday)(.*)


这篇关于正则表达式从字符串中删除单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆