Trying to match string that starts with #1-9
note: #
is followed by a number from 1 to 9
and ends with #1-9
(or not).
Full string : "#1Lorem Ipsum is simply dummy text#2printing and typesetting industry"
Idea:
is to replace #1Lorem Ipsum is simply dummy text
with <span class="one">Lorem Ipsum is simply dummy text</span>
and #2printing and typesetting industry
with <span class="two">printing and typesetting industry</span>
so to replace #1-9
with <span class="number">
and append the ending tag </span>
at the end of each.
but:
let's say if the string has only one string starting with #1-9
like that :
"#1Lorem Ipsum is simply dummy text"
how could be putting </span>
at the end to close the <span>
tag.
i'm guessing maybe using the last "
at the end of words to prepend the closing </span>
tag before it, since no more #1-9
to stop before it, but without losing or replacing the last "
of the string.
so it becomes: "<span class="one">Lorem Ipsum is simply dummy text</span>"
Regex i've tried : (#[0-9])(.*?)(#|")
but this is only matching the first part #1
of the string and ignoring the #2
part (see full string).
I will be using php
to match and replace maybe using preg_replace
just need to find a way to the regex part first.
How can i achieve this?