Test if a string is regex

后端 未结 4 1732
遥遥无期
遥遥无期 2020-12-03 13:50

Is there a good way of test if a string is a regex or normal string in PHP?

Ideally I want to write a function to run a string through, that returns true or false.

4条回答
  •  清歌不尽
    2020-12-03 14:21

    Here is a good answer how to:

    https://stackoverflow.com/a/12941133/2519073

    if(@preg_match($yourPattern, null) === false){
        //pattern is broken
    }else{
        //pattern is real
    }
    

提交回复
热议问题