I need to bring a text to html tag, like this:
input: p1: Question 1
output: <h3>Question 1</h3>
or also
input: question 1: ¿question 1?
output: <h3>¿question 1?</h3>
The detail that I don’t get it, I have the following Regex rule.
([a-zA-Z])([1-9])(:)+(.*)?
and my result is:
<h3> Question 1</h3>
question 1: ¿question 1?
- In the first one I need to remove the space that is generated between
<h3>
and theQ
- In the second it doesn’t work for me at all
Could you help me in what I am failing in the regex rule?
3
Answers
The answer was, thanks to the user @User863
The regexp needs to match optional whitespace before the question number (to fix the second problem) and after the
:
(to fix the first problem).DEMO
There’s no need for
?
after(.*)
. Since.*
matches a zero-length string, you don’t need to mark it as optional.I’m not really sure why you have
+
after(:)
— do you really want to allow something likeQuestion 1:::::
?You can use a single capture group, and match optional horizontal whitespace chars with
h*
In the capture group, match at least a single non whitespace char with
S
Regex demo
In the replacement use the value of group 1: