$update_text= preg_replace("/(<a[^>]*>)\s*(.*?)\s*(<\/a>)/s", "$1\n\t$2\n$3", $text);
Have this :
<a href="#" class="example">
<img src="bg1.jpg">
text text
</a>
<a href="#" class="example">
text text
<img src="bg2.jpg">
text text
</a>
<a href="#" class="example">
<img src="bg3.jpg">
</a>
Want this :
<a href="#" class="example">
<img src="bg1.jpg">
text text
</a>
<a href="#" class="example">
text text
<img src="bg2.jpg">
text text
</a>
<a href="#" class="example">
<img src="bg3.jpg">
</a>
https://regex101.com/r/qo2N22/3
之间的所有行添加标签我想添加\t
所有$2
行,但仅应用于第一行。谁能帮助我?感谢。
答案 0 :(得分:-1)
我用preg_replace_callback做到了。谢谢@ chris85的建议。
package sample;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
public class Controller {
public TextField theight;
public TextField tweight;
public Label lbmi;
public Label lresult;
public void buttonclicked() {
double height;
double weight;
double bmi;
String result;
height = Double.parseDouble(theight.getText());
weight = Double.parseDouble(tweight.getText());
double square = height * height;
bmi = weight / square;
lbmi.setText("The BMI is " + bmi);
}
}