Answered

regular expression functions in the set_var command

Are regular expression functions supported in the set_var expression options?

I am trying to extract the nth character from a string of characters.   One way to do that is to use the regular expression functions "sub()" or "substr()"

Examples might look like this:

class_code = "abcdefghijkl"

 

Extracting the 6th string position would give be the letter "f"

Using these functions, 

sub("^.....(.)*", "\\1", "@class_code")

substr("@class_code",6, 6)

Currently what I get back is something that looks like:

 
Set @sixth_char=sub^.....(.)*, \\1, abcdefghijkl

or

Set @sixth_char=abcdefghijkl,6, 6

 

So, clearly the functions are not working the way I am using them.   If the functions do not work is there a method for extracting the nth string position.

 

 

0
3 comments
Avatar
Rex Feizi

Hi, 

You can extract the 6th letter using substring as the following:

 

 

0
Comment actions Permalink
Avatar
William Smith

Thanks Rex.  That appears to work.   It's always nice to learn something new.

0
Comment actions Permalink
Avatar
Rex Feizi

Great. Please post any other questions you have, we always try to respond as quick as possible

0
Comment actions Permalink

Please sign in to leave a comment.