How can I search for user names that contain a non-alphanumeric | Community
Skip to main content
stiegjo
Level 2
Feb 17, 2022 6:58 PM UTC
Solved

How can I search for user names that contain a non-alphanumeric

I would like to search for any users under home/users with a first or last name that contain a non-alphanumeric character. I've tried the following SQL2 but no luck:

 

SELECT * FROM [rep:User] AS user WHERE ISDESCENDANTNODE([/home/users]) AND [profile/familyName] is not null AND [profile/familyName] LIKE '%[^a-zA-Z0-9]%' AND [profile/givenName] is not null ORDER BY [profile/familyName]

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
lukasz-m
lukasz-mAccepted solution
New Participant
Feb 17, 2022 8:06 PM UTC

Hi @stiegjo, JCR query is not supporting regular expression. Some operators supports wild cards e.g.

  • LIKE supports: % and _
  • CONTAINS supports: * and OR

In your case I would simply use query to get all users and as a next step do the filtering on Java level.

You can also try to build a query that will check if specific (unwanted/special) char is included in givenName or familyName - so the other way around comparing to your current strategy. But I can image that this kind of query could be complex and maybe it will not give you the expected result.

2 replies

lukasz-m
lukasz-mAccepted solution
New Participant
Feb 17, 2022 8:06 PM UTC

Hi @stiegjo, JCR query is not supporting regular expression. Some operators supports wild cards e.g.

  • LIKE supports: % and _
  • CONTAINS supports: * and OR

In your case I would simply use query to get all users and as a next step do the filtering on Java level.

You can also try to build a query that will check if specific (unwanted/special) char is included in givenName or familyName - so the other way around comparing to your current strategy. But I can image that this kind of query could be complex and maybe it will not give you the expected result.

Translate
stiegjo
stiegjoAuthor
Level 2
Feb 17, 2022 8:20 PM UTC

Thanks @lukasz-m  

Translate