I need help with a Regex in JavaScript (for a Photoshop script) to match bold tags around words in a string. (not worried about italic or bolditalic at this time).
I don’t want to split the string at this stage, I just want to chop it up into certain alternating chunks into using match.
// Be <b>bold!</b> Be fabulous!
Should get match to // (“Be “, “bold!“, “Be fabulous!”) // line commented for obvious reasons
After that, I’ll remove the bold tags – unless Regex can do that in one pass – don’t underestimate it’s power!
This is what I have so far
(.*?)([<b>]+[S]+[</b>]+[s]+)+(.*)/g
Only it doesn’t match everything as seen here
Just for the record, before anyone suggests a much easier JS solution:
In the Photoshop DOM you can’t script regular text mixed with bold. You probably can with Action Manager code, but with generating text that could be a big headache.
To get around this (not an ideal solution) I’ll be using regular text & splitting it up at the appropriate places & swapping to bold.
2
Answers
[<b>]
is character class, use simply<b>
instead.and change
S
to[^<]
You can try:
Here is online demo
sample code:
output:
Better try with
String.split()
function:output: