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

Substitute variable in regex expression

mike_korcynski
New Contributor III

I have a mapper with json input like this:

$effective_code = โ€œ2138-HCOM-0546-01โ€
$course_code =โ€œ2138-HCOM-0546-01-12345|2138-HCOM-0546-EMR-12456โ€

I want an expression that will match โ€œ2138-HCOM-0546-01-12345โ€ out of course code.

I donโ€™t understand in a Snaplogic Mapper, how I can substitute the $effective_code into my regex match to execute as:

$COURSE_CODE.match(/2138-HCOM-0546-01-\d{5,}/g)

more generally:

$COURSE_CODE.match(/$effective_code-\d{5,}/g)

Anyone know how to do this?

1 ACCEPTED SOLUTION

tstack
Former Employee

The argument to match() takes a string that will be interpreted as a regular expression. So, you should be able to do:

$COURSE_CODE.match($effective_code + "-\\d{5,}")

View solution in original post

3 REPLIES 3

tstack
Former Employee

The argument to match() takes a string that will be interpreted as a regular expression. So, you should be able to do:

$COURSE_CODE.match($effective_code + "-\\d{5,}")

mike_korcynski
New Contributor III

@tstack, thanks, that worked. I find the documentation on match() a little confusing:

https://docs-snaplogic.atlassian.net/wiki/spaces/SD/pages/1439357/String+Functions+and+Properties#St...

Mostly that it doesnโ€™t return a String, it returns a RegExpResult, and that it can take either a quoted regex or a typical /regex/, maybe this could be clarified in the wiki?

Thanks for your help.

Mike

dmiller
Admin Admin
Admin

Iโ€™ve forwarded your request to the Doc team.


Diane Miller
Community Manager