Title: Php Regex Example
Last modified: February 3, 2017

---

# Php Regex Example

 *  [newbie0117](https://wordpress.org/support/users/newbie0117/)
 * (@newbie0117)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/php-regex-example/)
 * Hi,
 * Could you possibly add an example to the description tab that uses regular expression.
 * Ie. Show menu item to user roles containing the number “4” or roles that contain
   the letter “y”
 * Is it even possible?
 * Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [shazdeh](https://wordpress.org/support/users/shazdeh/)
 * (@shazdeh)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/php-regex-example/#post-8872324)
 * That is possible, although a bit tricky, as sometimes the user has multiple roles
   so you have to watch for that. You could do something along the lines of:
 *     ```
       preg_match( '/4/', join( '|', $GLOBALS['current_user']->roles ) )
       ```
   
 * What comes between `//` is the Regex, that will check if any of the user roles
   contains the number 4.
 *  Thread Starter [newbie0117](https://wordpress.org/support/users/newbie0117/)
 * (@newbie0117)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/php-regex-example/#post-8872383)
 * What about primary role only?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Php Regex Example’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/menu-items-visibility-control.svg)
 * [Menu Item Visibility Control](https://wordpress.org/plugins/menu-items-visibility-control/)
 * [Support Threads](https://wordpress.org/support/plugin/menu-items-visibility-control/)
 * [Active Topics](https://wordpress.org/support/plugin/menu-items-visibility-control/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/menu-items-visibility-control/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/menu-items-visibility-control/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [newbie0117](https://wordpress.org/support/users/newbie0117/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/php-regex-example/#post-8872383)
 * Status: not resolved