1

Good day! Using this one:

#\[img\]([^\/\\]*\.(jpg|jpeg|gif|png|bmp))\[/img\]#si

I wanna replace the text with this one:

<img src="$1"/>

The error is: Warning: preg_replace(): Compilation failed: missing terminating ] for character class

I have tested it on regex101.com, it works well in preg_match mode.

P.S. Is the first one safe enough? Thanks!

8
  • it matches [img]file.jpg[/img] well Commented Mar 9, 2018 at 18:43
  • this works for me [img]([^\/\\\]*\.(jpg|jpeg|gif|png|bmp))[/img] Commented Mar 9, 2018 at 18:53
  • you've probably missed a symbol, thanks! Commented Mar 9, 2018 at 18:53
  • so this is solved? I was just about to ask if you have a URL to a shared regex from regex101 that I could take a look... Commented Mar 9, 2018 at 18:54
  • Damn! This solution has worked for me! Get it back! XD Commented Mar 9, 2018 at 18:55

1 Answer 1

2

You need to escape the closing ]

Change:

#\[img\]([^\/\\]*\.(jpg|jpeg|gif|png|bmp))\[/img\]#si

to:

#\[img\]([^\/\\\\]*\.(jpg|jpeg|gif|png|bmp))\[/img\]#si
Sign up to request clarification or add additional context in comments.

Comments

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.