Regex search problem/question

Regex search problem/question

amweiss98amweiss98 Posts: 12Questions: 4Answers: 1

I took the code for searching with regex (https://datatables.net/examples/api/regex.html) and put it on my server here
https://www.thrivezone.org/z2.php
I changed the table to demonstrate my problem by changing some names to 'alum' and 'balum'
To find only records with alum (and not balum), I would usually use this expression
[^b]alum
But this returns nothing. If my regex expression is correct, why isn't it returning anything?
Thanks

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,591Questions: 26Answers: 5,006

    I tried your test page and it returns a search result. Whether I use the global or name column and enable regex searching for [^b]alum returns rows with both alum and balum. If I change the search to ^[^b]alum then only rows with alum are displayed.

    Kevin

  • amweiss98amweiss98 Posts: 12Questions: 4Answers: 1

    Thanks Kevin...not sure why it works this way, but it does work.

  • kthorngrenkthorngren Posts: 21,591Questions: 26Answers: 5,006

    not sure why it works this way, but it does work.

    In what way are you referring?

    Kevin

  • amweiss98amweiss98 Posts: 12Questions: 4Answers: 1

    why you need two ^ when you only need to eliminate one character...that's what I don't understand..anyway, thanks

  • kthorngrenkthorngren Posts: 21,591Questions: 26Answers: 5,006
    edited May 2017 Answer ✓

    You are right. Both of us had the wrong regex. Your regex needs to be more like this:
    \b(?!b)\w*alum\b

    With this you will get alum, 'calum(or any character(s) before alum exceptb. The\b` is a word boundary.

    With this [^b]alum there needs to be one character (but not b) before alum to match. Which is why alum did not produce any results.

    Kevin

  • amweiss98amweiss98 Posts: 12Questions: 4Answers: 1

    perfect...that works...thanks so much

This discussion has been closed.