0

My input is

String input = "I am doing <span id='icms'>test</span>on <span id='icms'>regex</span> exp."

Now My output is coming like

"regex exp"

But my output is needed like this

I am doing test on regex exp

So need help on the regex and matcher.

4

2 に答える 2

3

You need two replacements. First replace <span[^>]*id=['"]icms['"][^>]*>([^<]*)</span> by ' $1 ' (without the quotes; they just show you that you have to pre- and append a space) and then replace ' {2,}' (without the quotes again) by a single space.

Quick PowerShell test:

PS> "I am doing <span id='icms'>test</span>on <span id='icms'>regex</span> exp." -replace '<span[^>]*id=[''"]icms[''"][^>]*>([^<]*)</span>',' $1 ' -replace ' {2,}',' '
I am doing test on regex exp.
于 2012-07-20T13:49:05.933 に答える
1

The following sould capture every part that is not a tag, which seems to be what you want:

(?:(.*)<.*?>(.*))*

EDIT:

then for this specific tag :

(?:(.*?)<span id='icms'>([^<]*?)</span>(.*))*

于 2012-07-20T13:49:13.870 に答える