0

How get the text inside a custom bbcode,

[gallery] get this text [/gallery].

I am using this regex but it wont work

/^(.*)\[gallery.*?\[\/gallery\](.*)$/gmi
0

2 Answers 2

3

(new) try :

/\[gallery\](.*)\[\/gallery\]/g 

to return the value use

var result = str.match(regex); alert(result[1]);
Sign up to request clarification or add additional context in comments.

5 Comments

like this str.replace(/[gallery](*.)+[\/gallery]/i, '\$1')
var result = str.match(regex); alert(result[1]);
getting SyntaxError: invalid quantifier
Depending on the regex engine, this won't work if there are multiple gallery tags. The regex will match everything between the first opening gallery tag and the last closing gallery tag. To be safe, throw a ? after the greedy * to make it look like /\[gallery\](.*?)\[\/gallery\]/g.
@HowToPlease I suppose you would want to do it the lazy way, (*.)+ to handle multiple tags within the same string
0

It looks like there may be some attributes after inside your tag.

Try this:

/\[gallery[^\]]*\](.*)\[\/gallery\]/gi

2 Comments

getting SyntaxError: invalid quantifier
This answer attempts to get a little too cute when searching for the opening tag. It's not necessary here. We already know that the opening tag needs to look exactly like this: [gallery]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.