cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Translate the entire conversation x

How to use regular expression in queryspec search condition.

Gajendra
4-Participant

How to use regular expression in queryspec search condition.

I have requirement to search object using queryspec which can have number with leading zero(to make it 8 digit length) or without leading zeros.

e.g. I am to search object number 66, query should be able to find object 66, 066, 0066 etc. I got regular expression to search( ^0*66$ ) need to know how to use in queryspec.

5 REPLIES 5
Fadel
23-Emerald I
(To:Gajendra)

Hi @Gajendra 

I wanted to see if you got the help you needed.

If so, please mark the appropriate reply as the Accepted Solution or please feel free to detail in a reply what has helped you and mark it as the Accepted Solution. It will help other members who may have the same question.

Of course, if you have more to share on your issue, please pursue the conversation.

Thanks,


Catalina
PTC Community Moderator
PTC
MTH
10-Marble
10-Marble
(To:Gajendra)

Try this

 

// Constant expression using LIKE pattern to match leading zeros
ConstantExpression ce = new ConstantExpression("%66"); // matches 66, 066, 0066, etc.
ce.setUseEscape(true);

// Create search condition
SearchCondition sc1 = new SearchCondition(ca, SearchCondition.LIKE, ce);

Gajendra
4-Participant
(To:MTH)

Hi,

Thank you for the reply. %66 will also match to 166, 266 or any number with trailing 66? My requirement is get number 66 or with leading zeroes.

HelesicPetr
22-Sapphire II
(To:Gajendra)

Hi @Gajendra 

Generally, queryspec does not support regular expressions. You have to combinate the substitute sql characters as "_" for one character or "%" for multiple characters. 

PetrH

Announcements
Top Tags