# Regex Trouble

**URL:** <https://forum.kirupa.com/t/regex-trouble/274724>\
**Category:** programming\
**Created:** [November 3, 2008, 5:08pm UTC](https://forum.kirupa.com/t/regex-trouble/274724 "2008-11-03T17:08:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neolumi](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/neolumi/32/1306_2.png) [@Neolumi](https://forum.kirupa.com/u/Neolumi)\
**Post date:** [November 3, 2008, 5:08pm UTC](https://forum.kirupa.com/t/regex-trouble/274724/1 "2008-11-03T17:08:23Z")

</div>

Hey everyone,

I’m having a bit of trouble with some regex and I think I’m nearly there. Basically I need a rule which grabs whatever li element which doesnt contain a \<ul\> element.

So a match would be \<li\>hi\</li\> and not \<li\>\<ul\>\<li\>hi\</li\>\</ul\>\</li\>

Here’s what I have:

```php
$str = preg_replace_callback('/(<li>([^<ul>]*)<\/li>)/', "sort_lists_regex", $str);

```

The current issue is that I dont know how to specify the NOT the string ‘\<ul\>’, as I’m currently saying NOT \<, u, l, \>

Help please! 😕
