Just ran into a bit of an issue with my regex. I would like to match all content inside the square bracket tags.
Here is my regex: /(?:\[.*])(.*)(?:\[\/.*])/
I am running it against this content:
[TITLE]More Things[/TITLE]
[BODY]This is not working
still not working
nope, hasn't magically started working
I'd like to match double carriage returns[/BODY]
It will only match the single line tags at the moment. Any help is appreciated, thanks.
"\n" matches a newline character.
Regex recognizes common escape sequences such as \n for newline, \t for tab, \r for carriage-return, \nnn for a up to 3-digit octal number, \xhh for a two-digit hex code, \uhhhh for a 4-digit Unicode, \uhhhhhhhh for a 8-digit Unicode.
Multiline option, or the m inline option, enables the regular expression engine to handle an input string that consists of multiple lines. It changes the interpretation of the ^ and $ language elements so that they match the beginning and end of a line, instead of the beginning and end of the input string.
This answer is not useful. Show activity on this post. [] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9.
If you're on php, you just need to add s
modifier. And also it's better to capture the opening tag and refer it while writing pattern for the closing tag.
/(?:\[([^\]]*)\])(.*?)(?:\[\/\1\])/s
If you're on javascript then you must need to turn each .
in the above regex to [\S\s]
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With