0

Hi,

here i just try to delete the content in text file between S and e letter.
but i don't know to write the ReplaceAll() methode after this

String[] paras = Pattern.compile("^(S)(.*)(e)$").split(inputText);

How could i use ReplaceAll() here?

Thank you

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Neversleepin
0

So you're using this pattern to split on - doesn't that eliminate anything that matches the pattern? If I split "a+b+c" on "+", I get ["a", "b", "c"] - what happens when you run this on

Anyone
Someone
Something
Somebody
Science
Some other word


I would expect

["Anyone","Something","Somebody","Some other word"]

based on the behavior of split in other contexts.

Also, this pattern should find only lines starting with "S" and ending with "e", so "Someone" would match, but "Somebody" would not, I think.
You would want "Something" and "winSome" and "handSomely" to match, I think. If so, remove the anchors. Then you're going to have to deal with greedy/non-greedy matching. I believe greedy matching is usually the default, so "'Stop eating', Said he to Sue" would match once, on the whole string, but you'd want it to match three times.

Sorry this isn't very organized, but it's the end of the day, and I'm going home. Good luck, hope it helps a little.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.