Fonzzzie
Fonzzzie

Reputation: 11

How to remove a specific text with multiple slashes by Regex

I am quite new at Regex and would like to remove the following text:

1/10 2/10 3/10 4/10 5/10 6/10 7/10 8/10 9/10 10/10

I was thinking something like: /1(.*)10(.*)2(.*)10(.*)3(.*)10(.*)10/s

but this doesnt seem to do the trick, it does remove the text, but it removes some other things too. Some images also contain numbers, so it starts to remove from the number in the image on.

So what i am looking for is to remove the exact text as above only

Upvotes: 1

Views: 222

Answers (3)

Fonzzzie
Fonzzzie

Reputation: 11

Thanks for the help! As i mentioned i am new at Regex, so please forgive my teminology.

Anyway i have matched the text with /1.10.2.10.3.10.4.10.5.10.6.10.7.10.8.10.9.10.10.10/ and replaced it with a blank field and that has done the trick!

Thanks for the hints and the support, it is really appreciated!

Upvotes: 0

BlueMonkMN
BlueMonkMN

Reputation: 25601

If you want to remove that exact text, I suggest using string.Replace instead of using regular expressions... that is if you're using a language with a string replace function.

Upvotes: 1

drysdam
drysdam

Reputation: 8637

You have a couple of problems here.

1) You are matching multiple characters with .* when there's only one character there (either a slash or a space). You could simply use a . to match a single character.

2) You don't even need to do that. Why not use a literal, escaped slash \/ and space respectively?

Upvotes: 1

Related Questions