Try a json escape tool https://www.freeformatter.com/json-escape.html#ad-output
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.

And you can check my Regex.
Hi @Sinnbeck. Thanks for your help. I'm escape this result is ^[a-zA-Z0-9- \\p{Myanmar}]*$ but it's not working.
@shaungbhone how is it not working?
@shaungbhone can you copy paste the json in here so we can test it directly?
@Sinnbeck Thank you for your help. Please check
{
"validation": {
"rule": [
"required",
"regex:/^[a-zA-Z0-9- \p{Myanmar}]*$/",
"unique:posts",
"max:255"
]
}
}
@shaungbhone Hmm I cannot seem to get it working either. Have you tried creating an issue on their issue tracker? https://github.com/the-control-group/voyager/issues
@Sinnbeck Yes, regex is working. But voyager validation is JSON format \ I can't write like this. Thank you for your help.
@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"
]
}
}
@shaungbhone No two . I got it to work, so it should just be copy/paste :)
@shaungbhone You need to remove one of the \ to test it. That is what json_decode does.. So you end up with just one
@shaungbhone This is how I tested it. I created a json file on disk and loaded it with php. Then I decoded it.. as you can see it removed the first \
@Sinnbeck Thank you. It's working in English. Myanmar is not working. :(
@shaungbhone What do you mean? I assume you are testing it in the actual admin panel?
@Sinnbeck Pardon. Please check https://www.youtube.com/watch?v=YpaPmdi1n6I
@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 :(
@Sinnbeck Yeah I will. Thank you for your time.
@shaungbhone Anytime :) Perhaps link to this thread to show that you have indeed done some tests before posting
@shaungbhone good to hear. But I would say voyager still has a bug :)
@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.
@shaungbhone well as you originally said, you couldn't save it :)
Please or to participate in this conversation.