Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shaungbhone's avatar

Regular Expression with json

Hello guys, I'm using voyager admin. Admin validation is JSON format. So, I can't write like this "regex:/^[a-zA-Z0-9 \p{Myanmar}]*$/", I got an error. Do you know how can I write this? \ is giving me an error. Imgur

And you can check my Regex.

0 likes
22 replies
shaungbhone's avatar

Hi @Sinnbeck. Thanks for your help. I'm escape this result is ^[a-zA-Z0-9- \\p{Myanmar}]*$ but it's not working.

shaungbhone's avatar

@Sinnbeck Thank you for your help. Please check

{
    "validation": {
        "rule": [
            "required",
            "regex:/^[a-zA-Z0-9- \p{Myanmar}]*$/",
            "unique:posts",
            "max:255"
        ]
    }
}
shaungbhone's avatar

@Sinnbeck Yes, regex is working. But voyager validation is JSON format \ I can't write like this. Thank you for your help.

Sinnbeck's avatar

@shaungbhone Yeah I understand the issue :) But I think I got it working. Json parse will remove the extra \ making it work

Try this

{
   "validation":{
      "rule":[
         "required",
         "regex:/^[a-zA-Z0-9- \\p{Myanmar}]*$/",
         "unique:posts",
         "max:255"
      ]
   }
}
Sinnbeck's avatar

@shaungbhone You need to remove one of the \ to test it. That is what json_decode does.. So you end up with just one

Sinnbeck's avatar

@shaungbhone Ah yeah that does indeed seem like a bug. I suggest you report it on their issue tracker. I am not sure how they parse that json string, but it seems they are doing it wrong :(

1 like
Sinnbeck's avatar

@shaungbhone Anytime :) Perhaps link to this thread to show that you have indeed done some tests before posting

1 like
shaungbhone's avatar

@Sinnbeck voyager team said "it's an issue with Laravel or with your regex." I will test it fresh Laravel app and it's still I will open issues. Thank you.

Please or to participate in this conversation.