Tuesday, April 19, 2016

Regex string to match string that starts with XX and ends with YY

Below matches a string that starts with XX and ends with YY.
Case sensitive but doesnt account for spaces.
/g Global flag enabled

\bXX\S*YY\b

Example: (#1 and #4 are a match)
  1. XXX-asdsd-sdsd-sdsdYY
  2. -XX-asdsdf sdf df dgsdfgs-YYsds
  3. XX-sd fsdg sdfg sdfgsfgh sdfg sdYY
  4. XX-sdfd-sdfsdgb-sdgbsd-gbd-sdYY
Test:
http://www.regexpal.com/?fam=94689

No comments:

Post a Comment