Ok. I am not very good at regex. So that is my first problem.
But in my rule I have a string such as “Flight to Atlanta (DL 1961)”
I am trying to extract just the part in the parentheses (flight number) and trim out the space.
var flighttest= transform(“REGEX”, “((.*?))”, “Flight to Atlanta (DL 1961)”.toString())
I don’t seem to get anything back. Any suggestions? thanks!
Depends on how much of your flight number is expected to be constant.
If all flight numbers start with DL and are 4 digits long, you could try
just need whatever is in the parentheses. so ideally on this i would return “DL 1961” then i can trim out the space and end up with just “DL1961”
I also just noticed in the docs, there are 3 parameters in the transform() call…
“Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.” Jamie Zawinski
That is one of the more famous quotes in computer science. I couldn’t help myself.
transform("REGEX", ".*\((.*\).*", “Flight to Atlanta (DL 1961)”)
The expression says match all the characters between parens with zero or more characters before or after.
As the parentheses are used to mark the string, you have to escape them in the REGEX. I would try something like
var flighttest= transform("REGEX",".*\((.*?)\).*", "Flight to Atlanta (DL 1961)")
It may be that you have to use double escapes
"\\" (I did not manage to understand, when this is necessary yet )
Please be aware that you used the wrong quotation marks in your posting. This might be a problem, too. Maybe this was done by discourse…
You can’t use a method on a primitive, but as a String is already a String, you can simply omit this part.
EDIT: too slow…