i have this 2 string and want to change it to html tags
1 : bq. sometext /* bq.+space+sometext+space or return
in this string.i want to convert it to this that start with bq.+space and end with space or return
<blockquote author="author" timestamp="unix time in secs">sometext</blockquote>
in this string
2: [quote author="author" date="unix time in secs"]
some text
[/quote] /* start with [qoute and get the text of author property then get
sometext form between ']' and '[/qoute]
i want to convert them to this :
<blockquote author="author" timestamp="unix time in secs">sometext</blockquote>
this regext not worked!:
#\bq(.| )(.*?)\n#
You’ve got your escaping a bit mixed up there. Escaping the
bmakes it a word boundary. Not escaping the.makes it an arbitrary character, and putting.and the space in an alternation means “either… or…”. This regex should take care of your first example:The second one will cause you trouble if anyone ever nests this with
quotemarkup. But suppose there are noo otherquotesbetween[quote...]and[/quote], you could use something like this:This uses two lookaheads to find the attributes and captures their values in capturing groups
$1and$2. And all that without advancing the actual position in the string. The good thing about lookaheads is that this works independently of the of the two attributes. Then we match the rest of the opening tag, and then capture as little as possible (.*?) until we encounter[/quote].Working demo.