tags:

views:

75

answers:

2

Ok first off I am using built-in .NET regex this I what I was told I am using. I am using the group function A(.*?)B than I am replacing it with nothing (basically removing it). What I am doing is removing some unwanted stuff from the end of a url I am scraping.

But the problem is for "B" I am using the quote which needs to be in there. Is there a way to say remove everything between A and b But not A and B? But A and B has to be used as markers in this example. I hope I explained this well enough.

Just in case I didn't I'll use an example random words and spaces nothing to use as indicators on either site "example.com" sometimes space no space sometimes words letters, etc. Now I want example.com with the quotes but everything changes on each side including spaces.

But I need example.com including the quotes so I cant just use "(.*?)" because once I use the replace function it wont get the quotes which I need to keep.

Ok rewording this A(.*?)B replace essentially I am reving whats in between A and B with nothing which is fine But i want to keep A and B i cannot use any characters or words before or after A and B because they are random and change for example how would you remove this: "example.com" but keep the quotes when everything before the quotes and inside the quotes is changing.

A: 

I think you want to match (A).*?(B) and replace it with \1\2. The exact syntax for doing this depends on the language.

Mark Byers
+1  A: 

You can use lookaround assertion:

I don't know the exact syntax for the regex flavour you're using but you can adapt this to your language.

replace (?<=A).*?(?=B) by nothing
M42