LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  regexIsMatchl

    Employee
    Posted 02-18-2014 14:43

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: mary

    Hi
    I have a list of codes in a field, created by a reduce to list node, where the delimiter is a pipe (|).
    Further along the graph , I�m trying to identify records with a particular code and regexIsMatchl isn�t finding them when I just do this :- 'list'.regexIsMatchI("EFP*010").
    I know there are records with this value as when I change it and put a pipe in at the end of the code eg: - 'list'.regexIsMatchI("EFP*010|"), it finds them.

    Shouldn�t regexIsMatchI find the string anywhere in the field?

    I know in the data, there are a few records where the code exists NOT followed by the pipe so if I add it to the pattern, those ones would be missed.

    Is the issue with the pipe, or could the astrix in the code be causing the problem?


  • 2.  RE: regexIsMatchl

    Employee
    Posted 02-18-2014 21:11

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ejones

    Hi Mary,

    Yes. I suspect that both the asterix and the pipe are causing you problems.

    But, I think we may need more information to help you with this. Can you post some example data that it should and should not match?


  • 3.  RE: regexIsMatchl

    Employee
    Posted 02-18-2014 21:15

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ejones

    With regular expressions, any punctuation characters tend to do interesting things and they don't work like the wildcard matching you may be more familiar with.

    An asterix, *, indicates that whatever in front can be matched to zero or more repetitions of it. So EFP*010 would be matching EFPPPPP010 and EFPP010 and even EF010.

    A pipe character is used for an "either or" match. I really don't know what it does the way you have it. and would have to do some studying and testing with it to find out.

    If you want an asterix to match an asterix you put a back slash in front of it. This is true for any punctuation characters, and to be safe I always put an asterix in front of all punctuation characters in a regex that I want to match to themselves. For example, if I want to match to the string "EFP*010" the regex I would use is "EFP\*010". And if I want to match to "|EFP*010|" I would use the regex "\|EFP\*010\|". BUT ... (see next paragraph)

    In BrainScript we have one more thing to deal with. The backslash has a special meaning. It is used to represent certain characters that aren't easy to represent otherwise. For example, \n is for a line feed, \r is a carriage return, \" is for a double quote that does not indicate the end of the string, and \\ is for a simple single backslash character. SO ... (see next paragraph)

    The BrainScript code you would use to match to the string "EFP*010" would look like the following because you need two backslash characters to represent one,, 'list'.regexIsMatchI("EFP\\*010"). And to match "|EFP*010|" you need to do this: 'list'.regexIsMatchI("\\|EFP\\*010\\|").


  • 4.  RE: regexIsMatchl

    Employee
    Posted 02-19-2014 15:09

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: mary

    Thanks - backslash before the asterix has solved my problem