0

How to catch in PHP in the text with regex such a bbcode which has 2 possible constructions at once

[gcountry allow="XX,YY"] Text Here [/gcountry]
[gcountry deny="AA,BB"] Text Here [/gcountry]  

???

I need to find it, and regarding to IP address detect the country and replace the whole text with a Text Here if the country user comes from is an allowed one. The whole problem to find out such bbcode and parsed to have allow and deny values also.

2
  • 1
    what should be the output? Commented Feb 27, 2015 at 7:07
  • an array or several variables where I can see Allow or Deny values and the Text Here Commented Feb 27, 2015 at 7:09

1 Answer 1

1

This should work for you

\[gcountry (allow|deny)="([\s\S]*?)"\]([\s\S]*?)(?=\[\/gcountry\])

Capture group 1 contains the attribute name, allow or deny, 2 contains the value of the attribute, and 3 contains the text between the opening and closing tag.

Demo: https://regex101.com/r/vY6zQ1/2

Sign up to request clarification or add additional context in comments.

3 Comments

he doest want to know the allow and deny , he want the text here
I need allow deny, but the text here too. How I need to modify your example to get the text itself too?
@MR.GEWA My mistake, forgot to capture one group, I've updated it, it now captures the inner text.

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.