Sami
Sami

Reputation: 1491

PHP - Regular Expression to Remove Single Quotes From Beginning and End of a String

I have a string variable like $string = "'dj12JKmi3433Kl09'". How to remove the single quotes ' from the beginning and end of the string using a preg_replace function? Thanks for your help.

Upvotes: 2

Views: 515

Answers (1)

elixenide
elixenide

Reputation: 44851

You don't really need a regex for this; you can just use trim(), as in trim($string, "'").

If you really want a regex for some reason, this one would do it:

/^'+|'+$/

Just replace with ''.

Upvotes: 4

Related Questions