By using the tag regex I believe your difficulty is changing the #nome
of string, in your case I believe this solves:
foobar.replaceAll("(^|\\s)#hoje($|\\s)", "$1" + valorAtual + "$2");
Note: I tested it \\b
in place of (^|\\s)
and ($|\\s)
, but I don’t know why it had no effect.
In a simple example would look something like:
final String frasePadrao = "Eu gostaria de saber programar melhor #hoje";
final String fraseRegex = "(^|\\s)#hoje($|\\s)";
listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observable, String valorAntigo, String valorAtual)
{
minhaLabel.setText(
frasePadrao.replaceAll(fraseRegex, "$1" + valorAtual + "$2")
);
}
});
minhaLabel
would be a label where the text appears
Explaining the regex
(^|\\s)
search a space or start of the string
#hoje
search the word I would like to be replaced
($|\\s)
search space or string ending
I mean, that way you can write the #hoje
at any position of the string, avoiding conflict with other texts that could vary. Technically the \\b
should solve this of the spaces between the word, but I don’t know if it’s a Java behavior, it just doesn’t work:
"\\b#hoje\\b"
In other languages I had no problem using the \b
. However the (^|\\s)
and ($|\\s)
already answer to that
What should appear in listviews? And replace it with exactly what word? You can give examples of the expected result for the example you gave in the question?
– Woss