Click here to Skip to main content
15,905,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 2-Mar-18 7:33am
v2
Comments
Patrice T 1-Mar-18 17:59pm    
show your code
Member 13704136 2-Mar-18 12:55pm    
Your regular expression:
/
(^.*)-?(Monday)(.*)$
/

Your test string:
Sunday Monday 100

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

But I want result as "Sunday100"

trying it in Rubular.com
Patrice T 2-Mar-18 12:56pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.
PIEBALDconsult 1-Mar-18 18:12pm    
Yes.
PIEBALDconsult 2-Mar-18 19:02pm    
No, that'll never happen in Rubular (or whatever).

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

C#
System.Console.WriteLine ( System.Text.RegularExpressions.Regex.Replace ( "Sunday Monday100" , "(^.*)-?(Monday)(.*)$" , "$1$3" ) ) ;
 
Share this answer
 
Comments
Member 13704136 2-Mar-18 18:43pm    
Hi, i need the result using regex command only. Can not use any fucntion/parameters.
if I use this:
(^.*)-?Monday(.*)

it gives me results as 2 value Sunday and 100

But I need value as Sunday100..

Thanks. Help!
PIEBALDconsult 2-Mar-18 18:54pm    
What language? Regex is not a "command" and of course you'll need parameters.
You don't nee Regex for such as requirement, you can use String.Replace method[^]. See:
C#
string s = "Sunday Monday100";
Console.WriteLine(s.Replace("Monday", "")); //prints "Sunday 100"
 
Share this answer
 
Comments
Member 13704136 2-Mar-18 18:43pm    
Hi, i need the result using regex command only. Can not use any fucntion/parameters.
if I use this:
(^.*)-?Monday(.*)

it gives me results as 2 value Sunday and 100

But I need value as Sunday100

Thanks for your help
Maciej Los 3-Mar-18 3:57am    
As i mentioned, you don't need regex.
Quote:
I need the solution in Rubular.com as that works as per my tool.

Your problem is that this is not the purpose of 'Rubular.com'
'Rubular.com' is an helper tool to help you build a RegEx, nothing else.
What you with the matching groups is your business in your code, but we can't help you on the code you don't show.

[Update]
Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
 
Share this answer
 
v2
Comments
Member 13704136 2-Mar-18 13:43pm    
Thanks. I just need help in regex. Not sure what is code
Patrice T 2-Mar-18 13:49pm    
SHOW YOUR ACTUAL CODE AND EXPLAIN THE PROBLEM YOU HAVE.
Member 13704136 5-Mar-18 15:53pm    
I dont have any code as I mentioned earlier. It is a tool where I can put regex to manipulate the string values. When I use (^.*)-?Monday(.*)

It gives me results Match Group as:
1) Sunday
2) 100

But I need Match Group as:
1) Sunday100
Patrice T 5-Mar-18 16:36pm    
The problem is that it is not how that tool works!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900