function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Justin Cairns 9Justin Cairns 9 

Regex question for Ends with and special characters.

Regex Ends with and Special Characters Questions
I'm currently using regex to determine if a value begins with certain characters like this.  (?i)^(BN|LID).*   This would match a string beginning with BN or LID and be case insensitive.  

I'm struggling with the syntax to apply the same logic to ends with.  I know you use the $ for ends with but I'm not sure of the order.  would this be correct?  *.(?i)(BN|LID)$

Also does anyone know how I could include a dash in the logic?  So I would want to know if a string begins with "A-" or ends with "A-1"  
Best Answer chosen by Justin Cairns 9
prabhakaran Chockalingam 5prabhakaran Chockalingam 5
Please see if this works - '(?i)(^[B|L]-?[N|ID].*)|(.*[BN|LID]$)|(.*-\\d$)'
It works for strings like = BN*, B-N*, LID*, L-ID*, BN*-1 or LID*-9. offcourse case insensitive.
There may be a better expressions to solve this. lets wait to get the experts..