search

Home  >  Q&A  >  body text

Use regular expressions to replace text with HTML tags starting with a certain character.

<p>I need to convert text into HTML tags, like this: </p> <pre class="brush:php;toolbar:false;">input: p1: Question 1 output: <h3>Question 1</h3></pre> <p>or</p> <pre class="brush:php;toolbar:false;">input: question 1: ¿ question 1? output: <h3>¿ question 1?</h3></pre> <p>The detail I don't understand is that I have the following regex rule. </p> <pre class="brush:php;toolbar:false;">([a-zA-Z])([1-9])(:) (.*)?</pre> <p>And my result is:</p> <pre class="brush:php;toolbar:false;"><h3> Question 1</h3> question 1: ¿ question 1?</pre> <ul> <li>In the first example, I need to remove the space generated between <h3> and Q. <code></code></li> <li>In the second example, it doesn't work at all for me. </li> </ul> <p>Can you help me see where I'm going wrong in my regex rules? </p><p>Demo:</p><p><strong></strong></p>
P粉438918323P粉438918323475 days ago398

reply all(1)I'll reply

  • P粉138871485

    P粉1388714852023-07-28 00:16:24

    the answer is

    ([a-zA-Z ])+([1-9])(:)+\s*(.*)

    reply
    0
  • Cancelreply