tags:

views:

95

answers:

3

I Required a Regex for the below input string:

Input data - ANALYSE/xxxxxxxx:

In the string xxxxxx is any characters. Need a regex accordingly to figure it out

At the end the colon is there but i need to replace entire 'ANALYSE/xxxxxxxx:' with String.empty.

I want to replace the above string with String.empty

The regex which i used 'ANALYSE/.*' is not getting.

Provide me a regex.

+4  A: 

Do you really need a regex? Can't you just use

if (text.StartsWith("ANALYSE/"))

?

If you do definitely need a regex, just

ANALYSE/.*

will match appropriately. The removal side will depend on exactly what you want to do - if you could give a concrete example, that would make life easier.

Jon Skeet
The regex will match "ANALYSE/" as well. If there must be at least one 'x' use + instead of *.
Brian Rasmussen
@Brian: True. In the original question "any characters" is somewhat ambiguous...
Jon Skeet
I agree. It wasn't meant as a correction. Just additional info.
Brian Rasmussen
+1  A: 

Try ANALYSE/.*?:

Kerido
You are definitely right. You should explain though, and at least show it as `ANALYSE/.*?:` - at first glance it seems like an error. I almost added a similar answer (with `[^:]*`)
Kobi
@Kobi: Thanks man
Kerido
+1  A: 

Try building your own using this site: http://gskinner.com/RegExr/

sonstabo
Even better try using http://www.google.com to find a regex testing tool
rrrr